Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 尝试在GitLab上部署React.js项目时出错_Reactjs_Git_Gitlab - Fatal编程技术网

Reactjs 尝试在GitLab上部署React.js项目时出错

Reactjs 尝试在GitLab上部署React.js项目时出错,reactjs,git,gitlab,Reactjs,Git,Gitlab,我正在GitLab中推送我的代码,一切都推送正常,但当我尝试将React.js项目部署到GitLab时,出现了下一个错误: 早些时候,我在GitHub上部署了这个项目,一切正常 my package.json代码: { "name": "app", "version": "0.1.0", "private": true, "homepage": "h

我正在GitLab中推送我的代码,一切都推送正常,但当我尝试将React.js项目部署到GitLab时,出现了下一个错误:

早些时候,我在GitHub上部署了这个项目,一切正常

my package.json代码:

{
  "name": "app",
  "version": "0.1.0",
  "private": true,
  "homepage": "https://groupname.gitlab.io/projectName/",
  "dependencies": {
    "ellipsis-tooltip-react-chan": "^1.1.1",
    "gh-pages": "^3.1.0",
    "modal-simple": "^1.0.19",
    "node-sass": "^5.0.0",
    "paginering": "^1.0.6",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-scripts": "4.0.1",
    "reactjs-popup": "^2.0.4",
    "recharts": "^1.8.5",
    "styled-components": "^5.2.1",
    "web-vitals": "^0.2.4"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "deploy": "gh-pages -d build",
    "predeploy": "npm run build"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}
my.gitlab-ci.yml文件

我在GitHub上找到了这个解决方案,但它对我不起作用

image: node:7.9.0 # change to match your node version

cache:
  paths:
    - node_modules/

before_script:
  - npm install

test:
  stage: test
  script:
    - CI=true npm test

pages:
  stage: deploy
  script:
    - CI=true npm run build
    - rm -rf public
    - mv build public
  artifacts:
    paths:
      - public # GitLab pages serve from a 'public' directory
  only:
    - master # run on master branch


我解决了这个问题。这是因为我的真实节点(npm)版本与.gitlab-ci.yml文件中的不同

需要在终端中打印
节点--version
,并显示节点的当前版本(在我的示例中是12.18.3)

我将.gitlab-ci.yml文件更改为

image: node:12.18.3 # change to match your project's node version

cache:
  paths:
    - node_modules/

before_script:
  - rm -rf build
  - CI=false npm install

pages:
  stage: deploy
  script:
    - CI=false npm run build
    - rm -rf public
    - cp build/index.html build/404.html
    - mv build public
  artifacts:
    paths:
      - public
  only:
    - master
一切都部署好了