Case 1: variable name used instead of value
package.json:
{
"name": "example",
"config": {
"url": "localhost/dev"
},
"scripts": {
"watch": "browser-sync start --files \"./**/*, !.node_modules/, !src\" --proxy $npm_package_config_url"
}
}
$npm run watch
opens http://localhost:3000/$npm_package_config_url
in the browser, instead of http://localhost:3000/dev
So, $npm_package_config_url
is used as a string, not as a variable.
Case 2: command substitution is not working
{
{ ... },
"scripts": {
"rm:all": "npm rm $(ls -1 node_modules | tr '/\\n' ' ')"
}
}
Sub-command lists folders in node_modules.
Again, npm run rm:all
does nothing, because $(ls -1 node_modules | tr '/\\n' ' ')
is interpreted as a folder name.
ENV: windows 10 | npm 3.5.1 | node 4.2.2 | git-bash 2.6.0
A bit late, but on Windows you need to use %npm_package_config_url%
There's a potential package that will "fix" this for you (i.e. give you a work-around) (https://www.npmjs.com/package/cross-env) that was referenced in one of the npm issue posts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With