npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

'npm config set scope' in project directory sets scope globally

What I Wanted to Do

I wanted to set ‘scope’ (and ‘access’) in the .npmrc file in my project/package directory. The npm docs describe doing this exact thing here.

I changed to my project directory as instructed and issued the npm config set scope <scope> command.

What Happened Instead

The specified scope was set in ~/.npmrc, not the .npmrc in the current directory.

Reproduction Steps

$ mkdir foo
$ cd foo
$ npm init
$ touch .npmrc
$ npm config set scope test
$ cat .npmrc
(file is empty)
$ cat ~/.npmrc
(notice line containing 'scope=test')


Manually editing the project’s .npmrc file to add the scope setting works as expected.

Platform Info

$ npm --versions
{ foo: '1.0.0',
  npm: '6.4.1',
  ares: '1.15.0',
  cldr: '33.1',
  http_parser: '2.8.0',
  icu: '62.1',
  modules: '64',
  napi: '3',
  nghttp2: '1.34.0',
  node: '10.15.1',
  openssl: '1.1.0j',
  tz: '2018e',
  unicode: '11.0',
  uv: '1.23.2',
  v8: '',
  zlib: '1.2.11' }
$ node -p process.platform

Tested with node 11.10.1/npm 6.7.0 and the behavior is unchanged.

It seems to have been that way since the entire feature was introduced, in 0.1.27 (commit). It seems to be intentional too, as per this old issue:

So this would be a feature request (although a very sensible one), and I suppose the docs are just incorrect.