簡體   English   中英

Gitlab-CI:Nodejs 應用程序構建失敗

[英]Gitlab-CI: Nodejs application fails to build

我正在使用 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 和代碼質量有關

這些是 linter 錯誤。 檢查正在執行的 npm 腳本(可能在npm run build上),因為這可能正在運行您的 linter 並產生錯誤。

我建議你在本地運行相同的東西並修復它們:)

這看起來與 GitLab 完全無關

我能夠通過添加來解決我的問題

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"
  },

我推薦與您的解決方案完全相反的方法:在本地設置CI=true而不是在生產構建中將其設置為false 您可以更改“構建”腳本,或將CI=true添加到您的 .env 文件(如果不存在,請在項目的根級別創建它)。

此后,您應該修復您的警告(使用==和未使用的變量)。


補充說明:

我的一位資深同事建議不要使用CI=false來抑制警告,因為 javascript/typescript 不是最穩定的語言並且隱藏了重要的警告。

准確地說,您的錯誤顯示了禁用警告的有用程度:使用==!=的隱藏問題。 道格拉斯·克羅克福德 (Douglas Crockford) 在JavaScript 中稱他們為“邪惡的雙胞胎”是有原因的:好的部分,在這個StackOverflow對問題“應該使用哪個等於運算符(== vs ===)”的回答中有詳細說明在 JavaScript 比較中?”。

簡而言之:盡可能避免使用==!=並堅持使用它們的雙胞胎===!== 來自==運算符不合邏輯行為的鏈接答案的示例摘錄:

'' == '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

此外,您還有許多未使用的變量。 未使用的變量不提供任何值,反而會使閱讀代碼的人感到困惑,因為人們通常期望再次使用變量。

我遇到了同樣的問題並使用了 "build": "CI=false && react-scripts build" 它對我有用

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM