解决使用jenkins构建react项目失败
Jenkins构建react项目失败,报错如下:
yarn build
yarn run v1.22.17
$ node scripts/build.js
Creating an optimized production build...
Treating warnings as errors because process.env.CI = true.
Most CI servers set it automatically.
Failed to compile.
./src/pages/sacrifice/index.jsx
Line 1:17: 'PureComponent' is defined but never used
....省略一堆错误
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Build step 'Execute Windows batch command' marked build as failure
Finished: FAILURE
Treating warnings as errors because process.env.CI = true.CI模式会把所有的warning当做errors处理
,所以在服务器上自动执行命令会报错,我们只要把所有的warning解决掉就可以了。
解决方法
设置系统变量:
process.env.CI = false;