Search code examples
node.jsnpmnpx

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


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.


Solution

  • 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!