Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

npm

npx

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.

like image 978
mikemaccana Avatar asked Mar 03 '21 14:03

mikemaccana


People also ask

What version of node supports NPX?

js Package Runner. npx is a very powerful command that's been available in npm starting version 5.2, released in July 2017.

What is node npm NPX?

NPX: The npx stands for Node Package Execute and it comes with the npm, when you installed npm above 5.2.0 version then automatically npx will installed. It is an npm package runner that can execute any package that you want from the npm registry without even installing that package.

Is NPX same as npm?

NPM is a package manager used to install, delete, and update Javascript packages on your machine. NPX is a package executer, and it is used to execute javascript packages directly, without installing them.

What is NPX in NPM?

npx is a very powerful command that's been available in npm starting version 5.2, released in July 2017. If you don't want to install npm, you can install npx as a standalone package npx lets you run code built with Node.js and published through the npm registry.

What if I don't want to install NPM?

If you don't want to install npm, you can install npx as a standalone package npx lets you run code built with Node.js and published through the npm registry. Node.js developers used to publish most of the executable commands as global packages, in order for them to be in the path and executable immediately.

How do I run an arbitrary command from an NPM package?

npx -p <pkg>[@<specifier>] -c '<cmd> [args...]' This command allows you to run an arbitrary command from an npm package (either one installed locally, or fetched remotely), in a similar context as running it via npm run.

What happened to NPX package in V7?

npx The npxbinary was rewritten in npm v7, and the standalone npxpackage deprecated when v7.0.0 hits GA. npxuses the new npm execcommand instead of a separate argument parser and install process, with some affordances to maintain backwards compatibility with the arguments it accepted in previous versions.


1 Answers

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!

like image 101
Joe Sadoski Avatar answered Sep 20 '22 01:09

Joe Sadoski