ReactJs:`npm run build` 失败,退出状态为 1 [英] ReactJs : `npm run build` fails with Exit status 1

查看:99
本文介绍了ReactJs:`npm run build` 失败,退出状态为 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个创建 React 应用程序、单页应用程序 应用程序.

当我触发 npm run build 命令时,出现以下错误:

When I fire npm run build command, I get following error :

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 看起来像这样:

my package.json looks like this:

   {
  "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 上遇到过类似的问题,但它们没有帮助,所以请不要将其标记为重复.

I have been through similar questions on SO, but they didn't help, so kindly don't mark it as duplicate.

我被困在这里,感谢任何帮助.

I am stuck here, any help is appreciated.

完整的错误日志:

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 ]

删除 node_modules 和 package-lock.json 后,做了 npm install -> npm audit fix -> npm run build

After deleting node_modules and package-lock.json , did 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

推荐答案

步骤 1 - 彻底删除 react 应用
第 2 步 - 打开终端和 npm cache clean --force
第 3 步 - npm install -g update-node
第 4 步 - npm i -g npm-upgrade
第 5 步 - 创建 React 应用程序并且它可以工作

step 1 - delete the react app completely
step 2 - open terminal and npm cache clean --force
step 3 - npm install -g update-node
step 4 - npm i -g npm-upgrade
step 5 - create react app and it works

还要在您的环境变量中添加 npm 的路径 (C:\Program Files\nodejs\node_modules\npm\bin).

Also add path to npm in your environment variables (C:\Program Files\nodejs\node_modules\npm\bin).

这篇关于ReactJs:`npm run build` 失败,退出状态为 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆