"eslint: Permission denied" 通过 GitLab 在 Firebase 上部署 React 应用程序时

"eslint: Permission denied" when deploying React app on Firebase through GitLab

我目前正在尝试通过 GitLab 为我在 Firebase 上托管的 React 应用设置 CI。我正在努力克服这一点。还有其他一些 post 建议使用 sudo 但控制台告诉我找不到该命令。

如有任何帮助,我们将不胜感激。谢谢。

这是我当前的配置:

gitlab-ci.yml配置文件

image: node:10.15.3

cache:
  paths:
  - node_modules/

stages:
  - build
  - deploy
    
deploy_dev:
  stage: deploy
  script:
    - echo "Deploying to staging environment"
    - npm install -g firebase-tools
    - firebase deploy --token $FIREBASE_DEPLOY_KEY --project $CI_ENVIRONMENT_NAME
  environment:
    name: dev
  only:
    - master

Package.json

{
  "name": "react-app",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "bootstrap": "^4.4.1",
    "firebase": "^6.6.2",
    "firebase-functions": "^3.3.0",
    "moment": "^2.24.0",
    "node-sass": "^4.13.1",
    "react": "^16.12.0",
    "react-beautiful-dnd": "^11.0.5",
    "react-dates": "^20.3.0",
    "react-dom": "^16.12.0",
    "react-moment": "^0.9.7",
    "react-perfect-scrollbar": "^1.5.3",
    "react-router-dom": "^5.1.2",
    "react-scripts": "^3.3.0",
    "reactstrap": "^8.2.0",
    "recompose": "^0.30.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

控制台报错提示权限错误

 $ firebase deploy -m "Pipeline $CI_PIPELINE_ID, build $CI_BUILD_ID" --non-interactive --token $FIREBASE_DEPLOY_KEY --project $CI_ENVIRONMENT_NAME
 ⚠  functions: package.json indicates an outdated version of firebase-functions.
  Please upgrade using npm install --save firebase-functions@latest in your functions directory.
 === Deploying to 'cmd-dev-bbdc4'...
 i  deploying functions, hosting
 Running command: npm --prefix "$RESOURCE_DIR" run lint
 > functions@ lint /builds/cmdc/cmd/functions
 > eslint .
 sh: 1: eslint: Permission denied
 npm ERR! code ELIFECYCLE
 npm ERR! errno 126
 npm ERR! functions@ lint: `eslint .`
 npm ERR! Exit status 126
 npm ERR! 
 npm ERR! Failed at the functions@ lint 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!     /root/.npm/_logs/2020-02-03T01_51_09_788Z-debug.log
 Error: functions predeploy error: Command terminated with non-zero exit code126
 ERROR: Job failed: exit code 1

因此,通过一些实验,我能够确定我必须进入 'functions' 目录以及 运行 NPM 安装。我猜这是由于对 Firebase 项目的结构和节点包的根本误解。

我很想了解更多,所以如果有人分享一些关于这方面的读物,我将不胜感激。

最终得到如下所示的脚本。

deploy_dev:
  stage: deploy
  script:
    - echo "Deploying to staging environment"
    - npm install -g firebase-tools #--allow-root
    - npm ci #--allow-root
    - cd functions # required or would throw the "eslint: not found" error
    - npm ci
    - cd ..
    - firebase use --token $FIREBASE_DEPLOY_KEY $CI_ENVIRONMENT_NAME
    - firebase deploy -m "Pipeline $CI_PIPELINE_ID, build $CI_BUILD_ID" --non-interactive --token $FIREBASE_DEPLOY_KEY
  environment:
    name: dev