NPM scripts - config and command substitution variables do not work in package.json

Case 1: 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 used as a string, not as a variable.

Case 2: team replacement does not work

 { { ... }, "scripts": { "rm:all": "npm rm $(ls -1 node_modules | tr '/\\n' ' ')" } } 

The sub-command lists the folders in node_modules.

Again, npm run rm:all does nothing, because $(ls -1 node_modules | tr '/\\n' ' ') interpreted as the name of the folder.

ENV: windows 10 | npm 3.5.1 | node 4.2.2 | git - bash 2.6.0

+5
source share
1 answer

A bit late, but on Windows you need to use %npm_package_config_url%

There is a potential package that will β€œfix” this for you (that is, give you a workaround) ( https://www.npmjs.com/package/cross-env ) that was referenced in one of the problem reports on npm.

+6
source

Source: https://habr.com/ru/post/1237182/


All Articles