10

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.

1
  • 3
    See comment at the bottom of the page here - it suggests using --node-options instead.
    – RobC
    Mar 3, 2021 at 15:52

1 Answer 1

11

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!

3
  • 2
    With node 14, it's --node-arg (singular)
    – colinux
    Jan 11, 2022 at 10:18
  • You're correct, fixed it. Jan 11, 2022 at 15:54
  • @colinux rescued me twice, first with node arg, then on the second check of answer with plural... Jan 27, 2022 at 15:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.