反应:npm start 工作,npm run build 抛出 ELIFECYCLE 错误(errno 1)

Posted

技术标签:

【中文标题】反应:npm start 工作,npm run build 抛出 ELIFECYCLE 错误(errno 1)【英文标题】:React: npm start works, npm run build throws ELIFECYCLE error (errno 1) 【发布时间】:2020-10-26 16:03:29 【问题描述】:

我有一个 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

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

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

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

【问题讨论】:

我试过你的代码line 52上的public/index.html文件有问题&lt;body"&gt;而不是&lt;body&gt; @MuhammadUsamaAshraf OMG 就是这样,删除了“解决了这个问题。不敢相信这造成了多大的麻烦。非常感谢! 【参考方案1】:

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

以解决此问题。

【讨论】:

以上是关于反应:npm start 工作,npm run build 抛出 ELIFECYCLE 错误(errno 1)的主要内容,如果未能解决你的问题,请参考以下文章

json 并发脚本npm-run-all,静默模式npm start -s

Vue报错:npm run start npm ERR! missing script: start

Next.js 中的 npm run dev 和 npm run start 有啥区别?

“npm run dev”和“npm start”之间的区别

NextJS with Express:将文件复制到服务器并运行“npm run start”失败

npm start 不运行反应项目