umi项目构建时经常会出些幺蛾子,今天这个是执行到 chunk asset optimization (92%) 就不动了,然后就报下边的异常:
Webpack █████████████████████████ chunk asset optimization (92%)
TerserPlugin
Browserslist: caniuse-lite is outdated. Please run:
npx browserslist@latest --update-db
Why you should do it regularly:
https://github.com/browserslist/browserslist#browsers-data-updating
<--- Last few GCs --->
[88024:0x102d4f000] 581469 ms: Mark-sweep 2042.1 (2057.7) -> 2038.5 (2057.7) MB, 961.6 / 0.0 ms (average mu = 0.224, current mu = 0.151) allocation failure scavenge might not succeed
[88024:0x102d4f000] 582630 ms: Mark-sweep 2042.7 (2058.2) -> 2039.2 (2058.4) MB, 981.1 / 0.0 ms (average mu = 0.190, current mu = 0.155) allocation failure scavenge might not succeed
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 0x1009d6059]
Security context: 0x0b12a79808d1 <JSObject>
1: /* anonymous */ [0xb129d34e601] [path/code/xxx/node_modules/@umijs/deps/compiled/webpack/4/bundle4.js:~87103] [pc=0x3480eb46f0cc](this=0x0b1219e42901 <JSGlobal Object>,0x0b12dbab9059 <String[1]: (>,0x0b12f494c7f9 <Object map = 0xb12c809db29>)
2: SourceNode_walk [0xb123241cb99] [path/code/xxx/n...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x1011c96b5 node::Abort() (.cold.1) [/path/.nvm/versions/node/v12.18.0/bin/node]
2: 0x10009cae9 node::Abort() [/path/.nvm/versions/node/v12.18.0/bin/node]
3: 0x10009cc4f node::OnFatalError(char const*, char const*) [/path/.nvm/versions/node/v12.18.0/bin/node]
4: 0x1001ddbc7 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/path/.nvm/versions/node/v12.18.0/bin/node]
5: 0x1001ddb67 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/path/.nvm/versions/node/v12.18.0/bin/node]
6: 0x100365a65 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/path/.nvm/versions/node/v12.18.0/bin/node]
7: 0x1003672da v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/path/.nvm/versions/node/v12.18.0/bin/node]
8: 0x100363d0c v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/path/.nvm/versions/node/v12.18.0/bin/node]
9: 0x100361b0e v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/path/.nvm/versions/node/v12.18.0/bin/node]
10: 0x10036d9da v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/path/.nvm/versions/node/v12.18.0/bin/node]
11: 0x10036da61 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/path/.nvm/versions/node/v12.18.0/bin/node]
12: 0x10033b69a v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/path/.nvm/versions/node/v12.18.0/bin/node]
13: 0x10068d080 v8::internal::Runtime_AllocateInOldGeneration(int, unsigned long*, v8::internal::Isolate*) [/path/.nvm/versions/node/v12.18.0/bin/node]
14: 0x1009d6059 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/path/.nvm/versions/node/v12.18.0/bin/node]
15: 0x3480eb46f0cc
16: 0x3480eb45c158
上网查了下,基本上是加大内存来解决,于是在 package.json 的script中修改对应命令如下:
"scripts": {
"start": "umi dev",
"build": "cross-env NODE_OPTIONS=--max_old_space_size=4096 umi build",
...
}
再次打包还是不成功。
网上接着找,如何做编译提速, 这篇说明截图如下
这里又是跟内存有关,试着在config中加上相应配置
defineConfig({
nodeModulesTransform: {
type: 'none',
exclude: [],
},
......
}
再次编译,居然成功了。但没文章说的减少40%到60%的编译时间,跟之前是差不多少,但不重要,它能编译就行。
网友评论