.npmrc not properly applied when running Yarn via script

When running Yarn through a script in package.json, it seems to ignore properties from the .npmrc file in the project folder.

Example

package.json

{
  "name": "my-project",
  "license": "UNLICENSED",
  "version": "1.0.0",
  "main": "index.js",
  "dependencies": {
  },
  "devDependencies": {
  },
  "scripts": {
    "showconfig": "yarn config list"
  }
}

.npmrc

registry=https://example.com/repository/npm/
always-auth=true
_auth=xxxx

When running yarn config list I get back

yarn config v1.0.2
info yarn config
{ 'version-tag-prefix': 'v',
  'version-git-tag': true,
  'version-git-sign': false,
  'version-git-message': 'v%%s',
  'init-version': '1.0.0',
  'init-license': 'MIT',
  'save-prefix': '^',
  'ignore-scripts': false,
  'ignore-optional': false,
  registry: 'https://registry.yarnpkg.com',
  'strict-ssl': true,
  'user-agent': 'yarn/1.0.2 npm/? node/v8.5.0 darwin x64',
  lastUpdateCheck: 1505395389597 }
info npm config
{ registry: 'https://example.com/repository/npm/',
  'always-auth': true,
  _auth: 'xxxx' }

But when running yarn config list via the showconfig script – yarn run showconfig – I get back

yarn run v1.0.2
$ yarn config list
{ 'version-tag-prefix': 'v',
  'version-git-tag': true,
  'version-git-sign': false,
  'version-git-message': 'v%%s',
  'init-version': '1.0.0',
  'init-license': 'MIT',
  'save-prefix': '^',
  'ignore-scripts': false,
  'ignore-optional': false,
  registry: 'https://registry.yarnpkg.com',
  'strict-ssl': true,
  'user-agent': 'yarn/1.0.2 npm/? node/v8.5.0 darwin x64',
  lastUpdateCheck: 1505395389597,
  silent: '1' }
{ registry: 'https://registry.yarnpkg.com',
  'always-auth': true,
  _auth: 'xxx',
  silent: '1',
  auth: 'xxxx',
  'version-git-tag': true,
  'init-license': 'MIT',
  argv: '{"remain":[],"cooked":["setup"],"original":["setup"]}',
  'save-prefix': '^',
  'strict-ssl': true,
  'version-git-message': 'v%%s',
  'version-git-sign': '',
  'ignore-scripts': '',
  'user-agent': 'yarn/1.0.2 npm/? node/v8.5.0 darwin x64',
  'init-version': '1.0.0',
  'ignore-optional': '',
  'version-tag-prefix': 'v' }

It seems like it loads the global config once more in the second case and merges it into the NPM config. The same happens when running other Yarn commands, e.g. install. Shouldn’t the config be the same in both cases?

Node version: v8.5.0
Yarn version: 1.0.2
OS: macOS 10.12.6 (also tested on CentOS 7)

Author: Fantashit

1 thought on “.npmrc not properly applied when running Yarn via script

Comments are closed.