我有一个 Create React App,Single Page Application 应用程序。
当我启动 npm run build 命令时,出现以下错误:
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! roffice@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the roffice@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
我的 package.json 看起来像这样:
{
"name": "roffice",
"version": "0.1.0",
"private": true,
"dependencies": {
"bootstrap": "^4.3.1",
"chalk": "^2.4.2",
"child_process": "^1.0.2",
"jquery": "^3.4.1",
"jquery-ui": "^1.12.1",
"jquery-ui-dist": "^1.12.1",
"list-react-files": "^0.2.0",
"react": "^16.8.6",
"react-bell-icon": "^1.0.0",
"react-bootstrap": "^1.0.0-beta.9",
"react-confirm-alert": "^2.4.0",
"react-custom-scrollbars": "^4.2.1",
"react-datepicker": "^2.7.0",
"react-dom": "^16.8.6",
"react-global-configuration": "^1.3.0",
"react-idle-timer": "^4.2.5",
"react-input-calendar": "^0.5.4",
"react-modal": "^3.8.1",
"react-popper": "^1.3.3",
"react-router-dom": "^5.0.0",
"react-scripts": "^3.0.1",
"react-spinner-material": "^1.1.1",
"rxjs": "^6.4.0",
"rxjs-compat": "^6.4.0",
"save-file": "^2.3.1",
"sys": "0.0.1",
"underscore": "^1.9.1"
},
"scripts": {
"start": "set PORT=3006 && react-scripts start",
"build": "react-scripts --max_old_space_size=8192 build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app",
"globals": {
"window": true,
"ActiveXObject": true
}
},
"browserslist": [
">0.2%",
"not dead",
"not ie <= 11",
"not op_mini all"
]
}
我曾经在SO上遇到过类似的问题,但它们并没有帮助,因此请不要将其标记为重复。
我被困在这里,不胜感激。
编辑:
完整的错误日志:
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@6.4.1
3 info using node@v10.15.2
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle roffice@0.1.0~prebuild: roffice@0.1.0
6 info lifecycle roffice@0.1.0~build: roffice@0.1.0
7 verbose lifecycle roffice@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle roffice@0.1.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/chandrani.chatterjee/Desktop/New_Roffice/ROffice_React/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Users/chandrani.chatterjee/Library/Android/sdk/platform-tools/:/Users/chandrani.chatterjee/Desktop/sdk/platform-tools/:/Users/chandrani.chatterjee/Library/Android/sdk/platform-tools/:/Users/chandrani.chatterjee/Desktop/sdk/platform-tools/
9 verbose lifecycle roffice@0.1.0~build: CWD: /Users/chandrani.chatterjee/Desktop/New_Roffice/ROffice_React
10 silly lifecycle roffice@0.1.0~build: Args: [ '-c', 'react-scripts build' ]
11 silly lifecycle roffice@0.1.0~build: Returned: code: 1 signal: null
12 info lifecycle roffice@0.1.0~build: Failed to exec build script
13 verbose stack Error: roffice@0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:301:16)
13 verbose stack at EventEmitter.emit (events.js:189:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:189:13)
13 verbose stack at maybeClose (internal/child_process.js:970:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid roffice@0.1.0
15 verbose cwd /Users/chandrani.chatterjee/Desktop/New_Roffice/ROffice_React
16 verbose Darwin 17.7.0
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v10.15.2
19 verbose npm v6.4.1
20 error code ELIFECYCLE
21 error errno 1
22 error roffice@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the roffice@0.1.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
EDIT2:
删除node_modules和package-lock.json后,是否安装了npm-> npm审核修复程序-> npm运行build
出现以下错误:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x10003b1db node::Abort() [/usr/local/bin/node]
2: 0x10003b3e5 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
3: 0x1001a86b5 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
4: 0x100573ad2 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
5: 0x1005765a5 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/bin/node]
6: 0x10057244f v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
7: 0x100570624 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
8: 0x10057cebc v8::internal::Heap::AllocateRawWithLigthRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
9: 0x10057cf3f v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x10054c884 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
11: 0x1007d4894 v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x3716a5cdbe3d
答案 0 :(得分:0)
似乎您的应用程序在构建时内存不足。
尝试将其添加到您的package.json中:
"build": "node --max_old_space_size=8192 <entry_file_path> --progress --env.<dev/prod>"
您可以将8GB空间更改为4GB,然后尝试先构建 可以,只要4GB就可以了
答案 1 :(得分:0)
第1步-完全删除react应用
第2步-打开终端和npm cache clean --force
步骤3-npm install -g update-node
第4步-npm i -g npm-upgrade
第5步-创建react应用并且有效
还要在环境变量( C:\ Program Files \ nodejs \ node_modules \ npm \ bin )中添加npm的路径。
答案 2 :(得分:0)
您可以在Windows命令行中执行相同的操作吗 如果不起作用,请尝试通过添加
来增加空间内存"build": "node --max_old_space_size=8192 node_modules/.bin/react-scripts start --progress --env.prod"