几周前,运行
yarn tsc --noEmit
开始花费太长时间,甚至不可能在不因内存不足错误而崩溃的情况下运行它:
<--- Last few GCs --->
[3039:0x158078000] 140607 ms: Scavenge 2031.2 (2084.8) -> 2023.5 (2084.8) MB, 2.0 / 0.0 ms (average mu = 0.633, current mu = 0.461) allocation failure;
[3039:0x158078000] 140615 ms: Scavenge 2031.2 (2084.8) -> 2024.8 (2084.8) MB, 2.2 / 0.0 ms (average mu = 0.633, current mu = 0.461) allocation failure;
[3039:0x158078000] 140620 ms: Scavenge 2031.3 (2084.8) -> 2024.6 (2101.8) MB, 3.8 / 0.0 ms (average mu = 0.633, current mu = 0.461) allocation failure;
<--- JS stacktrace --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
MOER TRACE, etc.
指定编译器可以使用多少内存时,如下所示:
export NODE_OPTIONS="--max-old-space-size=8192"
然后运行:
yarn tsc --noEmit --extendedDiagnostics
它运行没有崩溃,最终,我得到了这个:
Files: 2017
Lines of Library: 9552
Lines of Definitions: 192247
Lines of TypeScript: 78753
Lines of JavaScript: 0
Lines of JSON: 1895
Lines of Other: 0
Identifiers: 332062
Symbols: 1907181
Types: 3051718
Instantiations: 41284341
Memory used: 4369905K
Assignability cache size: 304593
Identity cache size: 10450
Subtype cache size: 35521
Strict subtype cache size: 6134
I/O Read time: 0.29s
Parse time: 0.59s
ResolveModule time: 0.28s
ResolveTypeReference time: 0.00s
ResolveLibrary time: 0.00s
Program time: 1.31s
Bind time: 0.30s
Check time: 457.23s
printTime time: 0.00s
Emit time: 0.00s
Total time: 458.84s
458秒?这是怎么回事?我该如何解决/调试这个问题?我很确定我们没有 2,000 个文件。
这是我的
tsconfig.json
:
{
"compilerOptions": {
"allowJs": false,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"jsx": "react-native",
"lib": ["ES2016"],
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": true,
"strict": true,
"skipLibCheck": true,
"target": "ES2016",
"baseUrl": ".",
"paths": {
"@app/*": ["./src/*"],
"@assets/*": ["./assets/*"]
}
},
"include": ["./src", "./assets"]
}
这是我的所有文件夹,我在
src
的
assets
部分添加了
include
和
tsconfig
,其中存放我所有的代码(SVG、PNG)
当 VS Code 片段和 ESLint 变得异常缓慢以至于我不得不在没有它们的情况下编码时,这种情况也开始发生。我也不知道是什么原因造成的。
这是我半解决的方法:
@typescript/analyze-trace
源tsc --generateTrace anyFolderName
。如果该命令由于内存不足而超时,请先执行以下操作:export NODE_OPTIONS="--max-old-space-size=8192
(这是针对MacOS。8192=8gb,调整数字直到足够高)anyFolderName
。npx analyze-trace anyFolderName
。它将打印一长串热点日志,其中包含文件名和行号。Guide
中,他们对如何执行此操作有建议),要么在该文件顶部的@ts-nocheck
。就我而言,我解决了一些问题,重构了一些问题,其余的我无法解决的问题,我只是添加了
@ts-nocheck
。与以前一样,运行 tsc
现在需要大约 8 秒。 VSCode/Eslint 工作得很好。
就我而言,主要是包
use-form
存在类型问题。
在已接受的答案中添加更多内容(也许这将有助于一些谷歌搜索)我想指出我面临的问题与此问题相关https://github.com/redis/node-redis/ issues/1748在node-redis包中。
我正在使用
ReturnType<typeof createClient>
类型声明,并且已接受的答案引导至具有此类型声明的文件。通过将其更改为 any
,编译时间大幅缩短,从 5 分钟以上缩短到 4 秒。
希望对某人有帮助