Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Overriding package.json config values does not work. #3475

Closed
1 task done
stocksr opened this issue Jun 28, 2021 · 2 comments
Closed
1 task done

[BUG] Overriding package.json config values does not work. #3475

stocksr opened this issue Jun 28, 2021 · 2 comments
Assignees
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@stocksr
Copy link

stocksr commented Jun 28, 2021

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

https://docs.npmjs.com/cli/v7/configuring-npm/package-json#config descrbes a way of having a config object in your package.json obect and optinally overriding it from your local config.

A "config" object can be used to set configuration parameters used in package scripts that persist across upgrades. For instance, if a package had the following:

{
  "name": "foo",
  "config": {
      "port": "8080"
  }
}

and then had a "start" command that then referenced the npm_package_config_port environment variable, then the user could override that by doing npm config set foo:port 8001.

The override appears to have stopped working in v7, it would appear from RFC 21 that this is intentional.

npm_package_config_* Each key in the config object will be included, but npm will not override values with a : config value if one exists.

However

  1. It is still listed as a feature in the docs.
  2. It is very useful and no indication of a suitable alternative has been provided.

Expected Behavior

I would like this behaviour to be re-introduced or an alternative way of doing the same thing provided.

Steps To Reproduce

  1. In this environment...
    (npm version 7)
  2. With this config...
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "node -p process.env.npm_package_config_test"
  },
  "config": {
    "test":"It is NOT working"
  },
  "author": "",
  "license": "ISC"
}

  1. Run '...'
npm config set test:test "It Is Working"
npm run test
  1. See error...
    this is output
It is not working

Environment

Tested on

  • OS: Windows 10
  • Node: v14.15.1
  • npm: 7.19.0
@stocksr stocksr added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Jun 28, 2021
@wraithgar
Copy link
Member

The docs do need to be cleaned up to reflect the new behavior. As far as a suitable alternative, suggesting that would be best done through the rfc process.

@wu-lee
Copy link

wu-lee commented Oct 24, 2022

I agree with the OP: this was useful, and its removal is breaking things. So be it. But there still seems to be no recommendations for "suitable alternatives" to have come out of this process anywhere I can see?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

3 participants