记一次前端npm报错“ error Command failed with exit code 1.”

九尾cat / 2023-07-08 / 原文

记一次前端npm报错“ error Command failed with exit code 1.”

现象

 

 

 报错日志如下

script returned exit code 1
[2023-07-07 23:12:06] + yarn --cwd /root/workspace build:test
[2023-07-07 23:12:06] yarn run v1.22.4
[2023-07-07 23:12:06] $ dotenv -e .env.test node scripts/build.js
[2023-07-07 23:12:07] shouldUseSourceMap------x-x--> false
[2023-07-07 23:12:07] isEnvProduction------x-x--> true
[2023-07-07 23:12:07] Creating an optimized production build...
[2023-07-07 23:12:07] Browserslist: caniuse-lite is outdated. Please run:
[2023-07-07 23:12:07]   npx browserslist@latest --update-db
[2023-07-07 23:12:07]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[2023-07-07 23:14:29] Browserslist: caniuse-lite is outdated. Please run:
[2023-07-07 23:14:29]   npx browserslist@latest --update-db
[2023-07-07 23:14:29]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[2023-07-07 23:14:29] Browserslist: caniuse-lite is outdated. Please run:
[2023-07-07 23:14:29]   npx browserslist@latest --update-db
[2023-07-07 23:14:29]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[2023-07-07 23:14:29] Browserslist: caniuse-lite is outdated. Please run:
[2023-07-07 23:14:29]   npx browserslist@latest --update-db
[2023-07-07 23:14:29]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[2023-07-07 23:14:29] Browserslist: caniuse-lite is outdated. Please run:
[2023-07-07 23:14:29]   npx browserslist@latest --update-db
[2023-07-07 23:14:29]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[2023-07-07 23:14:29] Browserslist: caniuse-lite is outdated. Please run:
[2023-07-07 23:14:29]   npx browserslist@latest --update-db
[2023-07-07 23:14:29]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[2023-07-07 23:14:29] Browserslist: caniuse-lite is outdated. Please run:
[2023-07-07 23:14:29]   npx browserslist@latest --update-db
[2023-07-07 23:14:29]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[2023-07-07 23:14:29] Browserslist: caniuse-lite is outdated. Please run:
[2023-07-07 23:14:29]   npx browserslist@latest --update-db
[2023-07-07 23:14:29]   Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating
[2023-07-07 23:14:30] 
[2023-07-07 23:14:30] Treating warnings as errors because process.env.CI = true.
[2023-07-07 23:14:30] Most CI servers set it automatically.
[2023-07-07 23:14:30] 
[2023-07-07 23:14:30] Failed to compile.
[2023-07-07 23:14:30] 
[2023-07-07 23:14:30] Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
[2023-07-07 23:14:30] 
[2023-07-07 23:14:30] resolve-url-loader: webpack misconfiguration
[2023-07-07 23:14:30]   webpack or the upstream loader did not supply a source-map
[2023-07-07 23:14:30] 
[2023-07-07 23:14:30] resolve-url-loader: webpack misconfiguration
[2023-07-07 23:14:30]   webpack or the upstream loader did not supply a source-map

分析原因

初步怀疑是代码缺少依赖,检查其他环境这个分支的发布发现正常编译,排除代码问题。

再次怀疑是nodejs版本有问题,检查正常编译的nodejs版本都为node-v14.20.0,排除了版本影响。

怀疑是打包机或缓存影响,切到香港节点的打包机,问题仍是一样复现,排除了打包机和缓存的问题。

最后经过仔细查看日志发现了问题所在  “Treating warnings as errors because process.env.CI = true.”

解决方法

修改编译的命令,指定env.CI = false即可。具体配置如下:

#原来编译命令
sh 'yarn --cwd ${PROJECT_PATH} build:test'

#修改编译命令
 sh 'export CI=false && yarn --cwd ${COS_UPLOAD_FROM_PATH} build:test --verbose'

总结

排查处理问题,还是需要从问题的现象和可能出现的因素去排查,日志是一个重要排查来源。

 

记一次前端npm报错“ error Command failed with exit code 1.”更多相关文章