记一次前端npm报错“ error Command failed with exit code 1.”
记一次前端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.”更多相关文章
JavaScript CSS Vue3 实现一个简单的Loading
配置和使用nvm免安装版本(nvm-noinstall.zip)
HarmonyOS:使用Node-API实现ArkTS与C/C++跨语言交互
【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (一):项目简介及安装依赖
【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (四):状态码的使用
【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (五):POST上传文件的设置
【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (六):token的设置
【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (七):MongoDB的设置
【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (三):Cors的设置及.env文件的设置
【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (二):项目文件夹架构及路由的设置
【NodeJS】NodeJS+mongoDB在线版开发简单RestfulAPI (八):API说明(暂时完结,后续考虑将在线版mongoDB变为本地版)
报error:0308010C:digital envelope routines::unsupported错--nodejs版本过高(nvm安装(更换)不同版本nodejs)
小结---安装nvm解决node版本不兼容的问题(node版本切换)