简体   繁体   English

Chromium:nvm与“npm_config_prefix”环境变量不兼容:

[英]Chromium: nvm is not compatible with the “npm_config_prefix” environment variable:

We are moving an Angular ( Angular, NgRx and Angular Material Starter ) based website from CircleCI to Shippable, and I'm now getting these failures: 我们正在将一个Angular( Angular,NgRx和Angular Material Starter )网站从CircleCI移动到Shippable,我现在遇到了这些失败:

27 05 2019 14:46:00.036:INFO [karma-server]: Karma v4.0.1 server started at http://0.0.0.0:9876/
27 05 2019 14:46:00.040:INFO [launcher]: Launching browsers ChromeShippable with concurrency unlimited
27 05 2019 14:46:00.071:INFO [launcher]: Starting browser Chrome
27 05 2019 14:46:01.326:ERROR [launcher]: Cannot start Chrome
        nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/build/versions/node/v10.14.1"
Run `unset npm_config_prefix` to unset it.

27 05 2019 14:46:01.327:ERROR [launcher]: Chrome stdout: 
27 05 2019 14:46:01.327:ERROR [launcher]: Chrome stderr: nvm is not compatible with the "npm_config_prefix" environment variable: currently set to "/build/versions/node/v10.14.1"
Run `unset npm_config_prefix` to unset it.

I can share more configuration, but the same code built fine in CircleCI and now is failing in Shippable. 我可以共享更多配置,但在CircleCI中构建的相同代码很好,现在在Shippable中失败了。 I can reproduce locally (on my local Docker) using the drydock/u16nodall image. 我可以使用drydock/u16nodall图像在本地(在我的本地Docker上) drydock/u16nodall

We are setting the following env vars prior to running npm: 我们在运行npm之前设置了以下env变量:

export PATH="./node_modules/.bin:$PATH";
export CHROME_BIN=chromium-browser;
export DISPLAY=:99.0;

Different NPM or Node versions don't seem to make a difference. 不同的NPM或Node版本似乎没有什么区别。

karma.conf.js has this: karma.conf.js有这个:

// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html

module.exports = function (config) {
  var isWatch = config.buildWebpack.options.watch;
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-spec-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../shippable/codecoverage'),
      reports: ['cobertura', 'html', 'lcovonly', 'json'],
      fixWebpackSourcePaths: true,
      thresholds: {
        statements: 80,
        lines: 80,
        branches: 72,
        functions: 80
      }
    },
    reporters: ['spec'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    customLaunchers: {
      ChromeShippable: {
        base: 'Chrome',
        flags: ['--no-sandbox','--disable-setuid-sandbox']
      }
    },
    browserNoActivityTimeout: 50000,
    singleRun: !isWatch
  });
};

All I've been able to find around the _not compatible npm_config_prefix_ error seems to be related to a corrupted node installation. 所有我能够找到_不兼容的npm_config_prefix_错误似乎与损坏的节点安装有关。 But installing a fresh version with NVM also shows this error. 但是使用NVM安装新版本也会显示此错误。

Any ideas how to get this working? 任何想法如何让这个工作?

I finally was able to overcome this issue by updating the customLauchers configuration to base off of ChromeHeadless instead of Chrome . 我终于能够通过将customLauchers配置更新为customLauchers ChromeHeadless而不是Chrome来解决此问题。

customLaunchers: {
  ChromeShippable: {
    base: 'ChromeHeadless',
    flags: ['--no-sandbox','--disable-setuid-sandbox']
  }
},

I'm not done chasing errors around the shippable migration, but at least this clears the error I was specifically asking about. 我没有完成围绕可移植迁移的错误,但至少这清除了我特别询问的错误。 I have already confirmed this ran fine (didn't crash when firing up Chrome) on the Shippable build boxes too. 我已经确认在Shippable构建盒上运行正常(在启动Chrome时没有崩溃)。

EDIT: Most of all the subsequent errors were also related to Chrome needing to be explicitly run as headless. 编辑:大多数后续错误也与Chrome需要明确运行无头有关。

Added to .pa11yci 's defaults : 添加到.pa11ycidefaults

"chromeLaunchConfig": {
  "args": ["--no-sandbox","--disable-setuid-sandbox","--disable-dev-shm-usage"]
}

Added to e2e/protractor.conf.js 's exported capabilities : 添加到e2e/protractor.conf.js的导出capabilities

'chromeOptions': {
  args: [ '--headless', '--disable-gpu', '--no-sandbox','--disable-setuid-sandbox','--disable-dev-shm-usage']
}

There were plenty other changes outside the scope of this question. 在这个问题的范围之外还有很多其他变化。

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

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