简体   繁体   English

在 gitlab 生产中未找到 cross-env 但可用于暂存

[英]cross-env not found on gitlab production but works on staging

I use gitlab CI to deploy vuejs app.我使用 gitlab CI 来部署 vuejs 应用程序。 For staging, everything works great.对于分期,一切都很好。 I copy paste the same configuration for production and I have :我复制粘贴相同的生产配置,我有:

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

Here is the .yml file :这是 .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

I also tried to manually clean cache on gitlab but no effect.我也尝试在 gitlab 上手动清理缓存但没有效果。

In staging steps are exactly the same and everything works, how can I deal with it ?分期步骤完全相同,一切正常,我该如何处理?

Why do you not install cross-env globally?为什么不全局安装cross-env

npm install --global cross-env

I successfully tested this solution with the node:latest image, the same you're using in the CI:我使用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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM