Asen Arizanov
Asen Arizanov

Reputation: 1000

Variables are not substituted in npm scripts on Windows

I cannot figure out how to use variables in npm scripts on Windows 8, npm 3.10.10 and node 6.11.1.

package.json:

{
  "name": "my-project",
  "scripts": {
    "start": "echo $npm_package_name"
  }
}

and npm start outputs:

> echo $npm_package_name

$npm_package_name

For some reason, the variable does not substituted. Any help will be greatly appreciated!

Articles being read- https://docs.npmjs.com/misc/scripts and variables-in-npm-scripts

Upvotes: 0

Views: 827

Answers (1)

Asen Arizanov
Asen Arizanov

Reputation: 1000

Variables on Windows should be surrounded/escaped with % %. The example above should be:

{
  "name": "my-project",
  "scripts": {
    "start": "echo %npm_package_name%"
  }
}

More info could be found here.

Upvotes: 2

Related Questions