Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use variables with npm 7.x.x in package.json?

I'd like to access keys in directories using npm script for it.

  "directories": {
    "client": "client",
    "server": "server"
  },
  "scripts": { 
    "test:client": "npm run local-tests --prefix ./$npm_package_directories_client", 
  }

But after updating npm from 6.x.x to 7.5.x I'm not allowed to do that anymore.

How I can do that with the new npm?

Thanks

like image 573
Vladyslav Zuiev Avatar asked Nov 29 '25 03:11

Vladyslav Zuiev


1 Answers

I could solve it by moving my variables under "config": {…}.

Like so:

  "config": {
    "directories": {
      "client": "client",
      "server": "server"
    }
  },
  "scripts": { 
    "test:client": "npm run local-tests --prefix ./$npm_package_config_directories_client", 
  }

See https://docs.npmjs.com/cli/v7/configuring-npm/package-json#config

like image 157
Christian Lutz Avatar answered Nov 30 '25 16:11

Christian Lutz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!