简体   繁体   中英

Can't find globally installed npm packages in Travis ci

The .travis.yml file is:

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

On the install stage, @octokit/rest package is installed. But in the second deploy task, when I required it in the first line of ./bin/auto_release.js :

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

Travis CI showed that Error: Cannot find module '@octokit/rest' .

The project is available at https://github.com/jjyyxx/JSONSchemaSimulator .

The ci report is available at https://travis-ci.org/jjyyxx/JSONSchemaSimulator/builds/408414549 .

So I haven't worked with Travis CI before, but I'm using GitLab CI and actually had the same situation.

The problem is, that the global packages will not be incorporated into the cache for the jobs, and therefore will be removed after install has finished.

For this kind of setup, I highly recommend installing the packages locally, not globally.

One of the reasons for this is that an executor might be used for different build jobs, where it would be very unfortunate if different package versions are installed globally and interfere with each other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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