cli icon indicating copy to clipboard operation
cli copied to clipboard

`npm config` fails in workspaces

Open jeffrson opened this issue 3 years ago • 11 comments

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

jeffrson avatar Jan 27 '23 22:01 jeffrson

npm config get registry also causes the same error , in the node:lts-buster docker image with npm version 9.3.1

anilkeshav27 avatar Feb 09 '23 15:02 anilkeshav27

+1 . We are using node:lts-buster for our builds and are facing same issue.

niteshagrawalgmail avatar Feb 09 '23 15:02 niteshagrawalgmail

This also breaks all the workflows that use actions/setup-node where workspaces are involved and cache is enabled, like this one (source)

ferferga avatar Feb 19 '23 15:02 ferferga

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.

john-landgrave avatar Mar 20 '23 21:03 john-landgrave

When will this bug be fixed?

kongmoumou avatar Sep 09 '23 13:09 kongmoumou

+1 we're also facing failures in our pipeline after upgrading from node 16 -> 18 due to this issue

vritant24 avatar Sep 14 '23 16:09 vritant24

I also ran into this issue today. Using Node.js v18.17.0 and NPM v10.2.5 and v9.6.7

davidstenstroem avatar Dec 07 '23 08:12 davidstenstroem

Running into this issue across multiple environments in office and remote the last 48 hours.

prodkt avatar Dec 07 '23 12:12 prodkt

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.

darcyclarke avatar Dec 08 '23 17:12 darcyclarke

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

jfly avatar Feb 23 '24 21:02 jfly

Seriously? Is it a problem to read the config from workspace? Why is not still fixed?

ThePlenkov avatar Apr 17 '24 20:04 ThePlenkov