簡體   English   中英

ReactJs:`npm run build` 失敗,退出狀態為 1

[英]ReactJs : `npm run build` fails with Exit status 1

我有一個Create React App,單頁應用程序。

當我觸發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 ]

編輯2:

刪除 node_modules 和 package-lock.json 后,是否 npm install -> npm audit fix -> npm run 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

看起來您的應用程序在構建時內存不足

嘗試在你的 package.json 中添加這個:

"build": "node --max_old_space_size=8192 <entry_file_path> --progress --env.<dev/prod>"

您可以將 8GB 空間更改為 4GB 並嘗試先構建,如果可行,您應該可以使用 4GB

第 1 步 - 完全刪除反應應用程序
第 2 步 - 打開終端和npm cache clean --force
第 3 步 - npm install -g update-node
第 4 步 - npm i -g npm-upgrade
第 5 步 - 創建反應應用程序,它的工作原理

還要在環境變量( C:\Program Files\nodejs\node_modules\npm\bin )中添加 npm 的路徑。

如果它不起作用,您可以在 Windows 命令行中執行相同的操作嘗試通過添加來增加空間內存

"build": "node --max_old_space_size=8192 node_modules/.bin/react-scripts start --progress --env.prod"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM