0

我使用 gitlab CI 部署 vuejs 应用程序。对于分期,一切都很好。我复制粘贴相同的生产配置,我有:

$ npm run build
> cross-env NODE_ENV=production && vue-cli-service build
sh: 1: cross-env: not found

这是 .yml 文件:

build-prod:
  stage: build-prod
  image: node:latest
  variables:
    NODE_ENV: production
  rules:
    # only run on master builds, we'll deal with branch builds next
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: on_success
    - when: never
  script:
    - node --version
    - npm --version
    - ls
    - cd front
    - ls
    - npm install -g @vue/cli-service@latest
    - rm -rf node_modules
    - npm install
    - npm install cross-env
    - npm run build <----------------------------------- Error here
    - ls

我也尝试在 gitlab 上手动清理缓存,但没有效果。

分期步骤完全相同,一切正常,我该如何处理?

4

1 回答 1

0

为什么不cross-env全局安装?

npm install --global cross-env

我用图像成功地测试了这个解决方案node:latest,与您在 CI 中使用的相同:

$ podman run --rm -it docker.io/node:latest bash
root@35ac5bda21eb:/# node --version
v16.12.0
root@35ac5bda21eb:/# npm --version
8.1.0
root@35ac5bda21eb:/# cross-env
bash: cross-env: command not found
root@35ac5bda21eb:/# export NODE_ENV=production
root@35ac5bda21eb:/# npm install --global cross-env

added 7 packages, and audited 8 packages in 1s

found 0 vulnerabilities
npm notice 
npm notice New patch version of npm available! 8.1.0 -> 8.1.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.1.1
npm notice Run npm install -g npm@8.1.1 to update!
npm notice 
root@35ac5bda21eb:/# which cross-env
/usr/local/bin/cross-env
于 2021-10-22T18:32:08.797 回答