Open jeffrson opened 1 year ago
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 cd
ing 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
&-iwr
are 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?
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).
@darcyclarke we have a scenario where we have a common ci script that uses npm config
and this ci job handles many repos. Until today none of them were a workspace project, so there was no issue.
is there some way at the cli i can ask npm if a project IS a workspace project in a bash script so i can use your approach only IF it is one? I've done some light google-ing and cant figure it out.
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
Since npm@9.3.0 calling
npm config list
ornpm config get registry
inside a workspace of a worktree results in an error:Here's part of the log:
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