【发布时间】:2020-10-20 11:03:36
【问题描述】:
每次尝试在 Ubuntu 机器(2 GB 内存,25 GB 存储)中创建我的 React 项目的生产版本 (npm run build) 时,我的 CI/CD 管道都会失败。
但是当我尝试在我的 Windows 机器上构建它时(8 GB 内存,1 TB 存储), 那么它正在成功构建,但它在 Ubuntu 机器 - 数字海洋上失败了。
我尝试通过运行以下命令来增加 Node 分配的默认内存 - export NODE_OPTIONS=--max_old_space_size=2048
但是,我仍然遇到了问题。
有没有其他方法可以增加 Node 为 React 项目分配的默认内存?
$ CI=false npm run build
> client@0.1.0 build /home/gitlab-runner-2/builds/WHJ93iRm/0/team-weanalyz/service-desk
> react-scripts build
Creating an optimized production build...
[12129:0x3441490] 163356 ms: Mark-sweep 994.2 (1005.1) -> 992.1 (1005.4) MB, 4996.1 / 0.1 ms (average mu = 0.068, current mu = 0.013) allocation failure scavenge might not succeed
[12129:0x3441490] 168187 ms: Mark-sweep 994.7 (1005.4) -> 993.0 (1006.6) MB, 4794.5 / 0.0 ms (average mu = 0.038, current mu = 0.008) allocation failure scavenge might not succeed
==== JS stack trace =========================================
0: ExitFrame [pc: 0x13cf099]
1: StubFrame [pc: 0x13d0133]
Security context: 0x21679f2408d1
2: SourceMapGenerator_serializeMappings [0x2ad643a32db1] [/home/gitlab-runner-2/builds/WHJ93iRm/0/team-weanalyz/service-desk/node_modules/source-map/lib/source-map-generator.js:~303] [pc=0x2cf51f68298d](this=0x2e99646fad91 )
3: SourceMapGenerator_toJSON [0x2ad643a32e31] [/home/gitla...
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0xa093f0 node::Abort() [node]
2: 0xa097fc node::OnFatalError(char const*, char const*) [node]
3: 0xb8431e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
4: 0xb84699 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
5: 0xd31055 [node]
6: 0xd316e6 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [node]
7: 0xd3df65 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [node]
8: 0xd3ee15 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
9: 0xd418cc v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
10: 0xd0837b v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
11: 0x1049fbe v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
12: 0x13cf099 [node]
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! client@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the client@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/gitlab-runner-2/.npm/_logs/2020-10-20T10_24_20_084Z-debug.log
ERROR: Job failed: exit status 1
【问题讨论】:
-
--max_old_space_size=4096不会在只有 2GB 内存的机器上做任何事情...
标签: node.js reactjs ubuntu digital-ocean