无法使用npm run build构建反应应用-退出状态1

时间:2018-11-02 14:34:34

标签: reactjs npm build npm-run

我已经使用create-react-app创建了一个react应用,当我第一次尝试使用npm run build构建它时,它运行良好。但是,经过几天的尝试,当我尝试运行相同的命令后,我面临以下问题。

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm- 
cli.js',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using npm@5.6.0
3 info using node@v8.11.4
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle nic-react@0.1.0~prebuild: nic-react@0.1.0
6 info lifecycle nic-react@0.1.0~build: nic-react@0.1.0
7 verbose lifecycle nic-react@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle nic-react@0.1.0~build: PATH: C:\Program 
Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp- 
bin;C:\Users\myaccount\nic-react\node_modules\.bin;C:\Program Files\Common 
Files\Microsoft Shared\Microsoft Online Services;C:\Program Files 
(x86)\Common Files\Microsoft Shared\Microsoft Online Services;C:\Program 
Files (x86)\Common Files\Volvo\VCOM Client\dll;C:\Program Files\Common 
Files\Volvo\VCOM Client\dll;C:\Program Files (x86)\Java\jre1.6.0_20\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft Windows Performance Toolkit\;C:\Program Files\dotnet\;C:\Program Files\Volvo\VCOM Server\bin;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Volvo\VComDNA\bin;C:\Program Files\IBM\WebSphere MQ\bin64;C:\Program Files\IBM\WebSphere MQ\bin;C:\Program Files\IBM\WebSphere MQ\tools\c\samples\bin;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files (x86)\Microsoft Team Foundation Server 2015 Power Tools\;C:\Program Files (x86)\LINQPad5;C:\ProgramData\chocolatey\bin;C:\Program Files (x86)\dotnet\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Users\myaccount\AppData\Local\Programs\Fiddler;C:\Program Files\Microsoft VS Code\bin;C:\Users\myaccount\.dotnet\tools;C:\Users\myaccount\AppData\Roaming\npm;C:\Users\myaccount\AppData\Local\Programs\Microsoft VS Code\bin
9 verbose lifecycle nic-react@0.1.0~build: CWD: C:\Users\myaccount\nic-react
10 silly lifecycle nic-react@0.1.0~build: Args: [ '/d /s /c', 'node 
scripts/build.js' ]
11 silly lifecycle nic-react@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle nic-react@0.1.0~build: Failed to exec build script
13 verbose stack Error: nic-react@0.1.0 build: `node scripts/build.js`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Program 
Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:285:16)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at EventEmitter.emit (events.js:214:7)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program 
Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at emitTwo (events.js:126:13)
13 verbose stack     at ChildProcess.emit (events.js:214:7)
13 verbose stack     at maybeClose (internal/child_process.js:925:16)
13 verbose stack     at Process.ChildProcess._handle.onexit 
(internal/child_process.js:209:5)
14 verbose pkgid nic-react@0.1.0
15 verbose cwd C:\Users\myaccount\nic-react
16 verbose Windows_NT 6.1.7601
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program 
 Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v8.11.4
19 verbose npm  v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error nic-react@0.1.0 build: `node scripts/build.js`
22 error Exit status 1
23 error Failed at the nic-react@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 ]

我一直在StackOverflow中四处寻找,但似乎找不到与我的问题类似的东西。通常会有一些特定的错误消息,但我看不到。

这是我的package.json:

{
 "name": "nic-react",
 "version": "0.1.0",
 "private": true,
 "dependencies": {
 "@fortawesome/fontawesome-svg-core": "^1.2.7",
 "@fortawesome/free-solid-svg-icons": "^5.4.2",
 "@fortawesome/react-fontawesome": "^0.1.3",
 "autoprefixer": "7.1.6",
 "axios": "^0.18.0",
 "babel-core": "6.26.0",
 "babel-eslint": "7.2.3",
 "babel-jest": "20.0.3",
 "babel-loader": "7.1.2",
 "babel-preset-react-app": "^3.1.2",
 "babel-runtime": "6.26.0",
 "case-sensitive-paths-webpack-plugin": "2.1.1",
 "chalk": "1.1.3",
 "chart.js": "^2.7.3",
 "core-js": "^2.5.7",
 "css-loader": "0.28.7",
 "dotenv": "4.0.0",
 "dotenv-expand": "4.2.0",
 "eslint": "4.10.0",
 "eslint-config-react-app": "^2.1.0",
 "eslint-loader": "1.9.0",
 "eslint-plugin-flowtype": "2.39.1",
 "eslint-plugin-import": "2.8.0",
 "eslint-plugin-jsx-a11y": "5.1.1",
 "eslint-plugin-react": "7.4.0",
 "extract-text-webpack-plugin": "3.0.2",
 "file-loader": "1.1.5",
 "fs-extra": "3.0.1",
 "html-webpack-plugin": "2.29.0",
 "i": "^0.3.6",
 "jest": "20.0.4",
 "moment": "^2.22.2",
 "object-assign": "4.1.1",
 "postcss-flexbugs-fixes": "3.2.0",
 "postcss-loader": "2.0.8",
 "promise": "8.0.1",
 "query-string": "^5.1.1",
 "raf": "3.4.0",
 "react": "^16.6.0",
 "react-bootstrap": "^0.32.4",
 "react-bootstrap-table": "^4.3.1",
 "react-chartjs-2": "^2.7.4",
 "react-copy-to-clipboard": "^5.0.1",
 "react-countup": "^4.0.0",
 "react-dev-utils": "^5.0.3",
 "react-flatpickr": "^3.6.4",
 "react-moment": "^0.7.9",
 "react-router-bootstrap": "^0.24.4",
 "react-router-dom": "^4.3.1",
 "react-select": "^2.1.1",
 "react-spinners": "^0.4.7",
 "react-toastify": "^4.4.0",
 "react-toggle": "^4.0.2",
 "resolve": "1.6.0",
 "style-loader": "0.19.0",
 "sw-precache-webpack-plugin": "0.11.4",
 "toastify": "^1.0.12",
 "url-loader": "0.6.2",
 "uuid": "^3.3.2",
 "webpack": "3.8.1",
 "webpack-dev-server": "2.11.3",
 "webpack-manifest-plugin": "1.3.2",
 "whatwg-fetch": "2.0.3",
 "xml-formatter": "^1.0.1"
}, 
 "scripts": {
 "start": "node scripts/start.js",
 "build": "node scripts/build.js",
 "test": "node scripts/test.js --env=jsdom"
},
"jest": {
  "collectCoverageFrom": [
   "src/**/*.{js,jsx,mjs}"
  ],
  "setupFiles": [
   "<rootDir>/config/polyfills.js"
 ],
 "testMatch": [
   "<rootDir>/src/**/__tests__/**/*.{js,jsx,mjs}",
   "<rootDir>/src/**/?(*.)(spec|test).{js,jsx,mjs}"
 ],
 "testEnvironment": "node",
 "testURL": "http://localhost",
"transform": {
  "^.+\\.(js|jsx|mjs)$": "<rootDir>/node_modules/babel-jest",
  "^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
  "^(?!.*\\.(js|jsx|mjs|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
},
"transformIgnorePatterns": [
  "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs)$"
],
"moduleNameMapper": {
  "^react-native$": "react-native-web"
},
"moduleFileExtensions": [
  "web.js",
  "js",
  "json",
  "web.jsx",
  "jsx",
  "node",
  "mjs"
   ]
},
  "babel": {
   "presets": [
   "react-app"
    ]
  },
"eslintConfig": {
  "extends": "react-app"
}
}

谢谢。

2 个答案:

答案 0 :(得分:0)

我发现了问题。 package.json中缺少react-scripts软件包。

要修复此问题,我运行了以下命令来安装它:

npm install react-scripts --save

完成后,执行npm运行脚本构建就可以正常工作。

答案 1 :(得分:0)

您可以在package.json中使用此代码

“脚本”:{ “ start”:“反应脚本开始”, “ build”:“反应脚本--max_old_space_size = 4096建立”, “ test”:“反应脚本测试”, “ precommit”:“ lint-staged” }