How do I use --node-arg in npx / npm version 7?
Asked Answered
N

1

13

npx used to have a --node-arg option to specify options for node. In npm v7, this results in:

npx: the --n argument has been removed.
See `npm help exec` for more information

Which states:

The --node-arg and -n options are removed.

Without any information being supplied about their replacement. This is not helpful.

I have tried using --. For example to run npx jest -t 'API work' with a node option of -r:

npx -r dotenv/config dotenv_config_path=/home/mike/Code/myapp/.env.local -- jest -t 'API works'

However this doesn't do anything.

Naughty answered 3/3, 2021 at 14:51 Comment(1)
See comment at the bottom of the page here - it suggests using --node-options instead.Leija
C
16

I just wanted to shout out RobC's Answer in the comments, as it did work for me. --node-arg has been replaced by --node-options. For example, with Fastify and Typescript:

// package.json
  "scripts": {
    ...
    "dev": "npx --node-options='-r dotenv/config' tsnd --respawn src/index.ts",
    ...
  },

Make sure to wrap all of your commands together in single quotes ('') if you're using it in a package.json!

Criticize answered 7/6, 2021 at 0:40 Comment(5)
With node 14, it's --node-arg (singular)Flint
You're correct, fixed it.Criticize
@Flint rescued me twice, first with node arg, then on the second check of answer with plural...Diabetes
I'm using node 18 and the correct option is --node-options and not --node-argIdleman
With NodeJS 20 (npm v10), even the --node-options didn't work for me. Instead I used NODE_OPTIONS="..." npx command variation to pass the args.Dachau

© 2022 - 2024 — McMap. All rights reserved.