`npm config` fails in workspaces
Is there an existing issue for this?
- [x] I have searched the existing issues
This issue exists in the latest npm version
- [X] I am using the latest npm
Current Behavior
Since [email protected] calling
npm config list or
npm config get registry
inside a workspace of a worktree results in an error:
❯ npm config list
npm ERR! code ENOWORKSPACES
npm ERR! This command does not support workspaces.
Here's part of the log:
28 timing npm:load:logFile Completed in 12ms
29 timing npm:load:timers Completed in 0ms
30 timing npm:load:configScope Completed in 0ms
31 timing npm:load Completed in 46ms
32 timing command:config Completed in 1ms
33 verbose stack Error: This command does not support workspaces.
33 verbose stack at Config.cmdExec (...\node_modules\npm\lib\base-command.js:123:29)
33 verbose stack at Npm.exec (...\node_modules\npm\lib\npm.js:154:20)
33 verbose stack at async module.exports (...\node_modules\npm\lib\cli.js:134:5)
It used to work in 9.2.0.
Expected Behavior
Well, show (and use!) all configs.
Steps To Reproduce
Build a worktree with packages. .npmrc in root. In a package call npm config list.
Environment
- npm: 9.4.0
- Node.js: 18.13.0
- OS Name: Windows 10
- System Model Name:
- npm config:
; copy and paste output from `npm config ls` here
npm config get registry also causes the same error , in the node:lts-buster docker image with npm version 9.3.1
+1 . We are using node:lts-buster for our builds and are facing same issue.
This also breaks all the workflows that use actions/setup-node where workspaces are involved and cache is enabled, like this one (source)
Just ran into this on a fresh install on a new machine. npm config set <...> fails with the following:
npm ERR! code ENOWORKSPACES
npm ERR! This command does not support workspaces.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/johnl/.npm/_logs/2023-03-20T21_34_37_668Z-debug-0.log
It looks like a workaround is to go down to 0.9.2? Considering that npm workspaces is what our app uses as it's "monorepo framework" I don't suppose I have a whole lot of choice there. Is this intentional, or this is a bug of some sort?
FWIW, I did also try cding up into the particular package and running the commands directly from there (no -w involved in the command anywhere) and it still failed with the same error I presume because it can tell that it is still in a workspace.
When will this bug be fixed?
+1 we're also facing failures in our pipeline after upgrading from node 16 -> 18 due to this issue
I also ran into this issue today. Using Node.js v18.17.0 and NPM v10.2.5 and v9.6.7
Running into this issue across multiple environments in office and remote the last 48 hours.
npm config is a bit of a special case since I'm fairly certain the npm team don't want to let users accidentally create local .npmrc files inside workspace directories (because they aren't supported/respected & could end up causing other issues for your project). Thus, failing within a workspace helps prevent that.
That said, if you really want to manage the config of your project from within a workspace, you can by passing --workspaces=false & --include-workspace-root (-ws=false & -iwr are shorthands for these options).
Minimum working reproduction:
npm init -y -iwr -w=a && cd ./a && npm config get registry -ws=false -iwr
And in the case of the original issue:
npm config list -ws=false -iwr # OR
npm config get registry -ws=false -iwr # will work...
If, for some reason, you are trying to create/manage nested .npmrc files in your workspaces, you'll have to get a bit tricky & use npm exec. Example:
npm exec -c 'npm config get registry -ws=false' -ws # OR whatever explicit workspace you want
With the above, you'll still want to include/exclude the root (ie. -iwr) if you're trying to manage both the workspace configs & the root's.
you can by passing
--workspace=false&--include-workspace-root(-ws=false&-iwrare shorthands for these options).
Since this tripped me up: it's --workspaces=false (plural).
edit: Just so there's a simple answer that people can actually copy paste, the following commands work for me inside of a npm workspace. Do read @darcyclarke's original post for a more nuanced answer, though.
$ npm config get --workspaces=false --include-workspace-root
$ npm config get -ws=false -iwr
Seriously? Is it a problem to read the config from workspace? Why is not still fixed?