Skip to content

[BUG] npm WARN ignoring workspace config at /my-project/my-workspace/.npmrcΒ #4605

Closed

Description

@JustinTRoss

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

npm ignores workspace .npmrc if running command from workspace directory.
This was encountered via CI loose allowance of node major version 16. The same CI job succeeded on 16.14.0 and failed on 16.14.2. Thus, it seems this was introduced in the npm minor version bumps included in node 16.14.1.

$ cd my-workspace
$ npm --version
npm WARN ignoring workspace config at my-project/my-workspace/.npmrc
...

This of course is a more pressing issue for commands like npm publish.

Expected Behavior

It should carry the same behavior it has had, which is to respect workspace .npmrc files.

Steps To Reproduce

  1. In node 16.14.2 with npm 8.5+
  2. With workspaces.
  3. Change directory into your workspace and run npm --version.
  4. See warning.

If you run this for npm publish, it will fail due to lack of necessary auth information set in .npmrc.

Environment

My local:

  • npm: 8.5.5
  • Node.js: 16.17.5
  • OS Name: MacOS and Debian
  • System Model Name: MBP
  • npm config:
; node bin location = /Users/me/.nvm/versions/node/v14.17.5/bin/node
; cwd = /Users/me/Repos/my-repo
; HOME = /Users/me

Activity

  1. added
    Bug
    Needs Triage
    Release 8.x
    on Mar 23, 2022
  2. changed the title [-][BUG] npm WARN ignoring workspace config at /my-workspace/.npmrc[/-] [+][BUG] npm WARN ignoring workspace config at /my-project/my-workspace/.npmrc[/+] on Mar 23, 2022
  3. ruyadorno commented on Mar 23, 2022

    @ruyadorno
    Contributor

    Hi @JustinTRoss, thanks for taking the time to reporting this.

    npm ignores workspace .npmrc if running command from workspace directory.

    That's intentional behavior, starting with npm@8.5.0 we shipped a new feature to make sure workspaces are properly tracked when running npm commands from within workspaces folders, ref: https://github.com/npm/cli/releases/tag/v8.5.0

    I see three different possible solutions:

    • In case all workspaces share the same auth values, using a single .npmrc file in the root folder should fix it
    • A possible way to handle different config values for publishing the workspaces is to use the publishConfig package.json value, ref: https://docs.npmjs.com/cli/v8/configuring-npm/package-json#publishconfig
    • If you want to continue using the values from the workspace folder .npmrc and force the npm cli to not track that as a workspace, you can opt-out of the default behavior by running your commands with --no-workspaces, e.g: npm publish --no-workspaces

    Hope that helps!

  4. removed
    Needs Triage
    on Mar 23, 2022
  5. JustinTRoss commented on Mar 24, 2022

    @JustinTRoss
    Author

    Thanks for the quick response. I understand that the behavior changed in 8.5, and I can understand the inspiration for the change. I'm confused however, why we would ship features that break the existing api in minor versions of npm and then include those changes in patch versions of NodeJS.

    Are there any resources you can point me to to adjust my expectations for when to expect breaking changes with regard to npm and how to insulate myself from them? Should I generally expect exposure to breaking changes anytime I don't lock Node and npm down to the patch?

  6. ljharb commented on Mar 24, 2022

    @ljharb
    Contributor

    Every bug fix is a potential breaking change, and vice versa. Since this one isn’t considered breaking, landing it in a mine is fine, and node would follow suit.

    It’s entirely possible it is breaking, but that can get subjective when you’re talking about undocumented behavior compared with the intentions of authors vs the expectations of users.

  7. ruyadorno commented on Mar 24, 2022

    @ruyadorno
    Contributor

    hi @JustinTRoss I believe @ljharb very eloquently explained the kind of trade offs we have to balance when working on fixes, new features and when to label them as breaking changes.

    To answer to your specific use case, running npm commands from workspaces folders was not a supported use case up to npm@8.5.0 as you can see the in our Working with Workspaces page the examples there will always refer to running commands from the root folder and using the -w config option to target a specific workspace, e.g: npm publish -w <workspace-name>. With that in mind we decided to label that a feature instead of a breaking change.

  8. JustinTRoss commented on Mar 24, 2022

    @JustinTRoss
    Author

    Thank you both for taking the time to explain πŸ™ .

    I think I understand now. It sounds like if this directory hadn't been listed as a workspace, it wouldn't have been affected. It's a sort of conflict of perspective on what behavior belongs to what subset of the API, here with vs without workspaces.

    As I understand it, npm uses local .npmrc from the current folder with package.json by design. When using workspaces however, there was no added functionality around .npmrc handling, so that default behavior was retained. When we introduced the workspaces-specific feature, we stopped deferring to the default behavior of local .npmrc and instead used the root .npmrc.

    Where I was thinking of workspaces as a modification on top of default behavior, it sounds like I should be thinking of it as a complete alternative where any defaulting to non-workspace behavior is just happenstance.

  9. added a commit that references this issue on Apr 14, 2022
  10. added a commit that references this issue on Jul 16, 2023
  11. added a commit that references this issue on Mar 6, 2024
  12. added a commit that references this issue on Sep 2, 2024
  13. added a commit that references this issue on Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugRelease 8.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions