Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.

npx -n on Windows broken since cmd-shim 3.x #5

Open
kevinbosman opened this issue Aug 31, 2019 · 5 comments
Open

npx -n on Windows broken since cmd-shim 3.x #5

kevinbosman opened this issue Aug 31, 2019 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@kevinbosman
Copy link

kevinbosman commented Aug 31, 2019

Since npm updated cmd-shim to v3.x (npm v6.11.0) it is no longer possible to pass node args to an pre-installed package via --node-arg/-n with Windows cmd.

This is due to the regex in findNodeScript() no longer matching the updated shims over here:

npx/index.js

Line 357 in 43d68c8

const cmd = /"%~dp0\\node\.exe"\s+"%~dp0\\(.*)"\s+%\*/

Reproduction steps

A simple example:

npm i uuid
npx -n -c uuid

This fails with:

ERROR: --node-arg/-n can only be used on packages with node scripts.
@tomyam1
Copy link

tomyam1 commented Dec 8, 2019

Still happens in [email protected]

Works after going back to npm 6.10.3 and doing npm rebuild in the folder I'm trying to use npx

@Den-dp
Copy link

Den-dp commented Jan 24, 2020

I really liked this feature.

It was handy for setting node options before npm package execution:

"scripts": {
  "start": "npx --node-arg=--max_old_space_size=4096 webpack-dev-server --mode development",
}

right now it looks way fragile (because I should know the wds package path)

"scripts": {
  "start": "node --max_old_space_size=4096 node_modules/webpack-dev-server/bin/webpack-dev-server --mode development"
}

@Den-dp
Copy link

Den-dp commented Aug 26, 2020

Just found that accordingly to https://blog.npmjs.org/post/626173315965468672/npm-v7-series-beta-release-and-semver-major the new npm v7 will get a new npx implementation (look at npx section in this article).

And also this article states that:

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

So it looks like this feature will be completely dropped 😕

@nathanblair
Copy link

Can it be documented more clearly exactly what the intention of npx/npm exec are for? At first it seemed like they were more or less a really functional alias for node node_modules/.bin. But now the ability to pass in node arguments is gone.

I feel like there's definitely a use case for them when it comes to being able to exec package cli tools without having to explicitly install the cli tool package or maintain the package as a devDependency when you only need the package for a single initialization command.

I'm thinking mostly this benefits projects like react, angular, and other front-end frameworks that leverage npx with their tool to initialize their framework into a directory and give the directory a template package.json that the developer can begin working with. I see a lot of value in npx here though admittedly it would be even nicer if the --node-args flag was still recognized.

@isaacs
Copy link
Contributor

isaacs commented Sep 9, 2020

Since npx now supports all standard npm configs (with the exception that -p is a shorthand for --package instead of --parseable), you can use --node-options instead of --node-args for any options you need to pass to node.

Eg, instead of npx -c 'do-something' --node-args='--abort-on-uncaught-exception --harmony-top-level-await' you'd do npx -c 'do-something' --node-options='--abort-on-uncaught-exception --harmony-top-level-await'.

See: https://docs.npmjs.com/using-npm/config.html#node-options

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants