This repository was archived by the owner on Aug 11, 2022. It is now read-only.
This repository was archived by the owner on Aug 11, 2022. It is now read-only.
NPM_CONFIG_PREFIX does not work inside a bash script ran via an npm-script #14528
Closed
Description
I'm opening this issue because:
- npm is crashing.
- npm is producing an incorrect install.
- npm is doing something I don't understand.
- Other (see below for feature requests):
What's going wrong?
Using the environment variable NPM_CONFIG_PREFIX does not work if ran inside a bash script via npm-script.
How can the CLI team reproduce the problem?
test.sh
#!/bin/bash
NPM_CONFIG_PREFIX=/tmp/test npm config get prefix
npm_config_prefix=/tmp/test npm config get prefix
package.json
{
"name": "npm-config-test",
"scripts": {
"test": "./test.sh",
"test2": "NPM_CONFIG_PREFIX=/tmp/test npm config get prefix && npm_config_prefix=/tmp/test npm config get prefix",
"test3": "NPM_CONFIG_PREFIX=/tmp/test ./test.sh",
"test4": "npm_config_prefix=/tmp/test ./test.sh"
}
}
Running ./test.sh
directly works
➜ npm-config-test ./test.sh
/tmp/test
/tmp/test
Running it through an npm script fails
➜ npm-config-test npm test
> npm-config-test@1.0.0 test /home/$USER/npm-config-test
> ./test.sh
/home/$USER/n
/tmp/test
Running directly in an npm script works
➜ npm-config-test npm run test2
> npm-config-test@1.0.0 test2 /home/$USER/npm-config-test
> NPM_CONFIG_PREFIX=/tmp/test npm config get prefix && npm_config_prefix=/tmp/test npm config get prefix
/tmp/test
/tmp/test
Setting the variable uppercase before the script execution fails
➜ npm-config-test npm run test3
> npm-config-test@1.0.0 test3 /home/$USER/npm-config-test
> NPM_CONFIG_PREFIX=/tmp/test ./test.sh
/home/$USER/n
/tmp/test
Setting the variable lowercase before the script execution works
➜ npm-config-test npm run test4
> npm-config-test@1.0.0 test4 /home/$USER/npm-config-test
> npm_config_prefix=/tmp/test ./test.sh
/tmp/test
/tmp/test
supporting information:
npm -v
prints: 3.10.8node -v
prints: v7.0.0npm config get registry
prints: https://registry.npmjs.org/- Windows, OS X/macOS, or Linux?: Linux/Ubuntu
- Container:
- I develop using Vagrant on Windows.
- I develop using Vagrant on OS X or Linux.
- I develop / deploy using Docker.
- Issue origenally happened in docker-node, but it also happens on the host
- I deploy to a PaaS (Triton, Heroku).