返回顶部

记一次前端nodejs 编译报错“Treating warnings as errors because process.env.CI = true”

记一次前端nodejs 编译报错“Treating warnings as errors because process.env.CI = true”

现象

 

 

 报错日志如下

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.”

解决方法

Coding

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

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

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

在CI环境中设置process.env.CI变量的方法因CI工具而异。

Travis CI

  1. Travis CI:在.travis.yml文件中添加env部分,设置CI变量为true

     
    env:
      - CI=true

CircleCI

.circleci/config.yml文件中添加environment部分,设置CI变量为true

environment:
  CI: true

 

Jenkins

在Jenkins的构建环境中设置环境变量CI=true

 

environment {
      CI = 'false'
}

 

GitLab CI/CD

.gitlab-ci.yml文件中添加variables部分,设置CI变量为true

 

variables:
  CI: "true"

 

 

总结

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

 

posted @ 2023-07-07 23:41  九尾cat  阅读(135)  评论(0编辑  收藏  举报