Gitlab-CI:Nodejs应用程序无法构建

dluptydi  于 2022-11-27  发布在  Git
关注(0)|答案(4)|浏览(231)

我正在使用gitlab-ci构建一个react应用程序,但构建阶段总是失败,在我的本地机器上,它可以正常工作,在我的部署服务器上也是如此,但当使用gitlab-ci时,它会失败,并显示

Line 421:34:   Expected '===' and instead saw '=='                     eqeqeq
  Line 473:13:   'names' is assigned a value but never used              no-unused-vars
  Line 789:96:   Expected '!==' and instead saw '!='                     eqeqeq
  Line 792:182:  Expected '!==' and instead saw '!='                     eqeqeq
  Line 792:258:  Expected '!==' and instead saw '!='                     eqeqeq
  Line 792:295:  Expected '!==' and instead saw '!='                     eqeqeq
  Line 793:161:  Expected '!==' and instead saw '!='                     eqeqeq
  Line 793:236:  Expected '!==' and instead saw '!='                     eqeqeq
  Line 793:272:  Expected '!==' and instead saw '!='                     eqeqeq
  Line 813:203:  Style prop value must be an object                      react/style-prop-object
./src/components/login.component.js
  Line 9:7:    'user' is assigned a value but never used                no-unused-vars
  Line 73:13:  'currentUser' is assigned a value but never used         no-unused-vars
  Line 73:26:  'showModeratorBoard' is assigned a value but never used  no-unused-vars
  Line 73:46:  'showAdminBoard' is assigned a value but never used      no-unused-vars
  Line 73:63:  'SuperAdmin' is assigned a value but never used          no-unused-vars
  Line 73:77:  'showAdminDirect' is assigned a value but never used     no-unused-vars
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! react-jwt-auth@0.1.0 build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the react-jwt-auth@0.1.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR!     /builds/tahar.benachour/endarh/.npm/_logs/2021-11-23T12_31_40_565Z-debug.log
Cleaning up file based variables
00:01
ERROR: Job failed: exit code 1

我尝试了不同图像,但出现相同错误
我的gitlab-ci.yml

stages:
  - setup
  - build
  - deployment

variables:
  npm_config_cache: "$CI_PROJECT_DIR/.npm"

image: node:10

# This folder is cached between builds
.dependencies_cache:
  cache:
    key:
      files:
        - package-lock.json # A transformer en package-lock.json
    paths:
      - .npm
    policy: pull

app-setup:
  stage: setup
  script:
    - npm ci
    - npm run build
  extends: .dependencies_cache
  cache:
    policy: pull-push
  artifacts:
    expire_in: 2h
    paths:
      - .npm
      - build/

一些额外的详细信息,我保存日志和构建目录作为工件,这里是日志详细信息

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'run', 'build' ]
2 info using npm@6.14.12
3 info using node@v10.24.1
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle react-jwt-auth@0.1.0~prebuild: react-jwt-auth@0.1.0
6 info lifecycle react-jwt-auth@0.1.0~build: react-jwt-auth@0.1.0
7 verbose lifecycle react-jwt-auth@0.1.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle react-jwt-auth@0.1.0~build: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/builds/tahar.benachour/endarh/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9 verbose lifecycle react-jwt-auth@0.1.0~build: CWD: /builds/tahar.benachour/endarh
10 silly lifecycle react-jwt-auth@0.1.0~build: Args: [ '-c', 'react-scripts build' ]
11 silly lifecycle react-jwt-auth@0.1.0~build: Returned: code: 1  signal: null
12 info lifecycle react-jwt-auth@0.1.0~build: Failed to exec build script
13 verbose stack Error: react-jwt-auth@0.1.0 build: `react-scripts build`
13 verbose stack Exit status 1
13 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:332:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid react-jwt-auth@0.1.0
15 verbose cwd /builds/tahar.benachour/endarh
16 verbose Linux 5.4.0-90-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "build"
18 verbose node v10.24.1
19 verbose npm  v6.14.12
20 error code ELIFECYCLE
21 error errno 1
22 error react-jwt-auth@0.1.0 build: `react-scripts build`
22 error Exit status 1
23 error Failed at the react-jwt-auth@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 ]

构建目录和文件创建成功,它在我的Web服务器上运行良好,所以老实说,我不理解管道故障,也许是因为说与lint和代码质量有关

ssgvzors

ssgvzors1#

我可以通过添加以下内容来解决问题
CI=false && react-scripts build到我的package.json

"scripts": {
    "start": "react-scripts start",
    "build": "CI=false && react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
tjjdgumg

tjjdgumg2#

这些是linter错误。检查正在执行的npm脚本(可能在npm run build上),因为这可能是运行您的linter并产生错误。
我建议你在本地运行同样的东西,并修复那些:)
这看起来和GitLab一点关系都没有

s4n0splo

s4n0splo3#

对于您的解决方案,我建议采用完全相反的方法:在本地设置CI=true,而不是将其设置为用于生产构建的false。您可以更改您的“build”脚本,或者将CI=true添加到您的.env-file(如果它不存在,请在项目的根级别创建它)。
之后,您应该修复出现的警告(使用==和未使用的变量)。

其他说明:

我的一位资深同事建议不要CI=false隐藏警告,因为javascript/typescript不是最稳定的语言,重要的警告被隐藏了。
准确地说,您的错误显示了如何禁用有用的警告:使用==!=时隐藏的问题。道格拉斯Crockford将它们称为JavaScript: The Good Parts中的“邪恶双胞胎”是有原因的,在这个StackOverflow answer中,针对“在JavaScript比较中应该使用哪个等号运算符(== vs ==)?"这个问题,我们进行了非常详细的阐述。
简而言之:尽可能避免使用==!=,坚持使用它们的孪生子===!==。示例摘录自==运算符不合逻辑行为的链接答案:

'' == '0'           // false
0  == ''            // true
0  == '0'           // true

false == 'false'    // false
false == '0'        // true

false == undefined  // false
false == null       // false
null  == undefined  // true

' \t\r\n ' == 0     // true

此外,你有很多未使用的变量,未使用的变量不提供任何值,反而会让阅读代码的人感到困惑,因为人们通常希望一个变量会被再次使用。

kx7yvsdv

kx7yvsdv4#

非常感谢你的这些建议,我不是开发人员,我只是为我的开发团队开发了一个CI/CD管道。他们仍然是初学者。

相关问题