React:npm开始工作,npm运行构建抛出ELIFECYCLE错误(errno 1)

发布时间:2020-07-06 13:55

我有一个React应用(使用create-react-app创建)。

npm start最初已经起作用,现在仍在起作用。

几天前我最初运行npm run build部署到Firebase托管时,它就可以了。 但是,今天,我注意到npm start仍然有效,但npm run build将引发以下错误:

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! fellon@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the fellon@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

完整的错误日志为:

0 info it worked if it ends with ok
1 verbose cli [
1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Users\\edwar\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build'
1 verbose cli ]
2 info using npm@6.14.5
3 info using node@v14.5.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle fellon@0.1.0~prebuild: fellon@0.1.0
6 info lifecycle fellon@0.1.0~build: fellon@0.1.0
7 verbose lifecycle fellon@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle fellon@0.1.0~build: PATH: C:\Users\edwar\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\edwar\Desktop\fellon\node_modules\.bin;C:\Users\edwar\Downloads\cmder\bin;C:\Users\edwar\Downloads\cmder\vendor\conemu-maximus5\ConEmu\Scripts;C:\Users\edwar\Downloads\cmder\vendor\conemu-maximus5;C:\Users\edwar\Downloads\cmder\vendor\conemu-maximus5\ConEmu;C:\Program Files (x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\php;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Git\cmd;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\nodejs\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\php;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Git\cmd;C:\Users\edwar\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Heroku\bin;C:\Users\edwar\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin;C:\Mingw-w64\i686-8.1.0-win32-dwarf-rt_v6-rev0\mingw32\bin;C:\Users\edwar\AppData\Roaming\npm;C:\Program Files\Git\usr\bin;C:\Program Files\Git\usr\share\vim\vim74;C:\Users\edwar\Downloads\cmder\
9 verbose lifecycle fellon@0.1.0~build: CWD: C:\Users\edwar\Desktop\fellon
10 silly lifecycle fellon@0.1.0~build: Args: [ '/d /s /c', 'react-scripts build' ]
11 silly lifecycle fellon@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle fellon@0.1.0~build: Failed to exec build script
13 verbose stack Error: fellon@0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (C:\Users\edwar\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:314:20)
13 verbose stack     at ChildProcess.<anonymous> (C:\Users\edwar\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:314:20)
13 verbose stack     at maybeClose (internal/child_process.js:1051:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
14 verbose pkgid fellon@0.1.0
15 verbose cwd C:\Users\edwar\Desktop\fellon
16 verbose Windows_NT 10.0.18362
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\edwar\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
18 verbose node v14.5.0
19 verbose npm  v6.14.5
20 error code ELIFECYCLE
21 error errno 1
22 error fellon@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the fellon@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 ]

我正在使用节点:v14.5.0 / npm:6.14.5 / react-scripts:3.4.1 / webpack:4.42.0

此React应用的代码为:https://github.com/travelingaries/Fellon

我尝试过但不起作用的一些方法是:

  1. npm cache clean --force =>删除node_modules和package-lock.json => npm install => npm run build
  2. yarn build而不是npm run build
  3. 将整个项目代码=> npm install克隆到新文件夹=> npm run start
  4. 更新节点和npm版本,然后尝试上述步骤
  5. 确保将system32添加到环境变量的PATH中(确认已添加)

我整天都在摆弄这个问题,而且我几乎没有其他选择。 如果有人可以为这个问题提出可行的解决方案,那将意味着很多。 提前非常感谢您!

回答1

就像在 Muhammad Usama Ashraf 的评论中一样,这是一个简单的语法错误,在我的案例中未被发现。 更改 以解决此问题。