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] Broken link in npm v7 series beta re. $npm_package_* environment variables (now gone) #2452

Open
dandv opened this issue Jan 7, 2021 · 8 comments
Assignees
Labels
Documentation documentation related issue Release 7.x work is associated with a specific npm 7 release

Comments

@dandv
Copy link

dandv commented Jan 7, 2021

Apologies if this is the wrong repo; I don't know where to file this.

I was researching why after upgrading to npm 7 my $npm_package environment variables were blank, and found this blog post. It says,

RFC 21 Environment no longer includes npm_package_* fields

Three issues,

  1. That RFC21 link has moved to implemented
  2. For others who land on this during the same kind of troubleshooting, it would really help to specify what the recommended alternative is.
  3. https://docs.npmjs.com/cli/v7/using-npm/scripts#packagejson-vars still mentions the v6 behavior.
@dandv dandv 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 Jan 7, 2021
StephenCleary added a commit to StephenCleary/blog-stephencleary-dotcom that referenced this issue Jan 14, 2021
@darcyclarke darcyclarke removed the Needs Triage needs review for next steps label Jan 29, 2021
@darcyclarke
Copy link
Contributor

Apologize for the confusion. We'll try & get that fixed.

@darcyclarke darcyclarke added pr: needs documentation pull request requires docs before merging and removed Release 7.x work is associated with a specific npm 7 release labels Jan 29, 2021
@derekgreer
Copy link

So, what is the recommended approach for custom package variables referenced by scripts? Should the config object be used for this purpose?

@darcyclarke darcyclarke added the Release 7.x work is associated with a specific npm 7 release label Jun 2, 2021
@lpicquet-metapack
Copy link

Yes, we this to automatically put docker tag and labels based on the values from package.json. It would be great to know how to circumvent the change and for the documentation to be up to date.

@ljharb
Copy link
Contributor

ljharb commented Sep 28, 2021

@derekgreer scripts should read package.json directly.

@wu-lee
Copy link

wu-lee commented Feb 2, 2022

I've just spent most of an hour trying to find some documentation indicating why, with recent versions of npm, my run-scripts are now deprived of access to the configuration parameters in .npmrc which used to be exposed via environment variables named with a prefix npm_package_config_.

The latest npm documentation does not seem to mention it. I have not seen any warnings that this was going to happen, or that it was bad practice to use these. There are no articles mentioning this I can find searching the wider internet. Now I seem to have been put in the awkward position of needing to find a work-around and implementing it in all my npm projects. I hope you can sympathise if I admit to feeling a little exasperated! :)

Can there please be some clear mention of this breaking change in the npm documentation, with advice as to a recommended work-around which will work both with older and newer versions of npm going forward?

Or better, could there be a way of enabling the old behaviour (perhaps a parameter in package.json) so I don't have to rewrite?

Thanks!

@ljharb
Copy link
Contributor

ljharb commented Feb 2, 2022

@wu-lee it was a breaking change in npm v7, and is listed in https://blog.npmjs.org/post/626173315965468672/npm-v7-series-beta-release-and-semver-major and npm/rfcs#90.

@wu-lee
Copy link

wu-lee commented Feb 2, 2022

Indeed, but also:

  • the link to RFC21 in that blog post is broken (as noted by the OP)
  • in both the information is hard to find even if you're looking for it (ditto these issues)
  • they do not explain what to do instead

I anticipate lots of other people are going to be caught out by the loss of this functionality, possibly in quite damaging ways, as shell scripts can do given an empty string where there was something else before. So it does seem to warrant at the very least a heads up for npm users in the documentation, where they're likely to look first when they realise something is wrong,..

And this would likely save the NPM team some grief too.

@ljharb
Copy link
Contributor

ljharb commented Feb 2, 2022

Certainly, at least, the github blog post should be updated to point to the proper RFC link (cc @ethomson).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation documentation related issue Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

8 participants