Skip to content

NPM_CONFIG_USERCONFIG seems broken #4568

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

Closed
timdp opened this issue Sep 28, 2017 · 1 comment
Closed

NPM_CONFIG_USERCONFIG seems broken #4568

timdp opened this issue Sep 28, 2017 · 1 comment
Assignees

Comments

@timdp
Copy link

timdp commented Sep 28, 2017

Do you want to request a feature or report a bug?

A bug.

What is the current behavior?

Setting npm_config_userconfig to a path to npmrc with //registry.npmjs.org/:_authToken=TOKEN_HERE doesn't seem to work anymore. The token is never read.

What is the expected behavior?

Installation should use the token from my custom npmrc during installation. Seb originally added support for this in #1519.

To be clear: what I'm doing is running this on a CI-like server, where users are able to supply their own registry token, allowing the server to install their private packages. I write the token to a temp file and pass the path to the file in the environment variable for the yarn process.

This worked with 0.28.4 and is broken in 1.x.

Thanks!

@BYK BYK self-assigned this Sep 29, 2017
BYK added a commit to getsentry/craft that referenced this issue Dec 2, 2020
This is a retake on #130. Although npm/cli#8 claims to have support
for `npm_config_//registry.npmjs.org/:_authToken=` usage, my tests
and the reports on the internet says this still doesn't work, even
with the latest npm (7.0.15 at the time).

The only way to pass the token is to have the `authToken` line in
an `.npmrc` file. The quick&dirty way would have been to create one
in the project directory but that may collide with a potentially
pre-existing project `.npmrc`. Trying to merge these seems more
trouble than it is worth:
https://github.com/actions/setup-node/blob/59e61b89511ed136a0b17773f07c349fa5c01e8b/src/authutil.ts
(even worse as you'd need to revert these changes after the fact)

The "better" solution I found is:

1. Create a temporary file as your npmrc
2. Put the token/registry line there
3. Tell npm to use that file as the user config
4. Use the `npm_config_userconfig` for the above to support yarn too

This may still fail for yarn, see yarnpkg/yarn#4568.
BYK added a commit to getsentry/craft that referenced this issue Dec 2, 2020
This is a retake on #130. Although npm/cli#8 claims to have support
for `npm_config_//registry.npmjs.org/:_authToken=` usage, my tests
and the reports on the internet says this still doesn't work, even
with the latest npm (7.0.15 at the time).

The only way to pass the token is to have the `authToken` line in
an `.npmrc` file. The quick&dirty way would have been to create one
in the project directory but that may collide with a potentially
pre-existing project `.npmrc`. Trying to merge these seems more
trouble than it is worth:
https://github.com/actions/setup-node/blob/59e61b89511ed136a0b17773f07c349fa5c01e8b/src/authutil.ts
(even worse as you'd need to revert these changes after the fact)

The "better" solution I found is:

1. Create a temporary file as your npmrc
2. Put the token/registry line there
3. Tell npm to use that file as the user config
4. Use the `npm_config_userconfig` for the above to support yarn too

This may still fail for yarn, see yarnpkg/yarn#4568.
@BYK
Copy link
Member

BYK commented Dec 2, 2020

Just tested this with yarn config list and it shows up under npm config section.

Closing for now but feel free to report back if this is still an issue.

@BYK BYK closed this as completed Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants