代码之家  ›  专栏  ›  技术社区  ›  obfish

在Travis ci中找不到全局安装的npm包

  •  1
  • obfish  · 技术社区  · 6 年前

    这个 .travis.yml 文件是:

    language: node_js
    node_js:
    - node
    env:
      global:
        - secure: "[redacted]"
    before_install:
    - node ./bin/version_check.js
    install:
    - npm i
    - npm i -g codecov
    - npm i -g @octokit/rest
    script:
    - npm run lint
    - npm run build
    - npm run ci
    deploy:
    - skip_cleanup: true
      provider: npm
      email: obfishstudio@gmail.com
      api_key:
        secure: "[redacted]"
      on:
        repo: jjyyxx/JSONSchemaSimulator
        branch: master
    - skip_cleanup: true
      provider: script
      script: node ./bin/auto_release.js
      on:
        repo: jjyyxx/JSONSchemaSimulator
        branch: master
    

    在安装阶段, @octokit/rest 已安装程序包。但是在第二个部署任务中,当我在 ./bin/auto_release.js :

    const Octokit = require('@octokit/rest')
    

    特拉维斯·西证明了 Error: Cannot find module '@octokit/rest' .

    该项目可在 https://github.com/jjyyxx/JSONSchemaSimulator .

    ci报告可在 https://travis-ci.org/jjyyxx/JSONSchemaSimulator/builds/408414549 .

    1 回复  |  直到 6 年前
        1
  •  3
  •   FatalMerlin    6 年前

    所以我以前没有和特拉维斯CI合作过,但我使用的是GitLab CI,实际上也有同样的情况。

    问题是,全局包不会合并到作业的缓存中,因此将在 install 已经完成。

    对于这种安装,我强烈建议在本地而不是全局安装包。

    其中一个原因是,执行器可能用于不同的生成作业,如果在全局范围内安装不同的包版本并相互干扰,这将是非常不幸的。