【问题标题】:Chromium: nvm is not compatible with the "npm_config_prefix" environment variable:Chromium:nvm 与“npm_config_prefix”环境变量不兼容:
【发布时间】:2019-05-27 16:04:42
【问题描述】:

我们正在将基于 Angular (Angular, NgRx and 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.

我可以共享更多配置,但相同的代码在 CircleCI 中构建良好,现在在 Shippable 中失败。 我可以使用 drydock/u16nodall 图像在本地(在我的本地 Docker 上)复制。

我们在运行 npm 之前设置了以下环境变量:

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

不同的 NPM 或 Node 版本似乎没有区别。

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
  });
};

我所能找到的关于 _not compatible npm_config_prefix_ 错误的所有信息似乎都与节点安装损坏有关。但是使用 NVM 安装新版本也会显示此错误。

任何想法如何使它工作?

【问题讨论】:

    标签: node.js npm chromium nvm shippable-ci


    【解决方案1】:

    我终于能够通过将customLauchers 配置更新为基于ChromeHeadless 而不是Chrome 来克服这个问题。

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

    我还没有完成围绕可交付迁移的错误,但至少这清除了我特别询问的错误。我已经确认这在 Shippable 构建盒上运行良好(启动 Chrome 时没有崩溃)。

    编辑:大多数后续错误也与 Chrome 需要明确地以无头方式运行有关。

    添加到.pa11ycidefaults

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

    添加到e2e/protractor.conf.js的导出capabilities

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

    在这个问题的范围之外还有很多其他的变化。

    【讨论】:

      猜你喜欢
      • 2018-11-28
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多