Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure npm run is being called instead of npx run #245

Closed
wants to merge 2 commits into from
Closed

Ensure npm run is being called instead of npx run #245

wants to merge 2 commits into from

Conversation

MarmadileManteater
Copy link

@MarmadileManteater MarmadileManteater commented Oct 28, 2022

Problem:

If you run npm-run-all using npx (EX: npx npm-run-all clean build:dev test), it will prompt you to install runjs if it is not already installed.

Screenshot_2022-10-28_13-41-05

Then, it will throw an error that looks something like this:
image

This is because running npx npm-run-all causes process.env.npm_execpath to point to npx instead of npm.

npm_cli_is_npx

The underlying command ends up something like npx run clean which will attempt to run runjs instead of running the npm scripts, and of course, clean isn't a javascript file or anything that runjs can do anything with, so that is why it throws.

For reference, this is what it looks like when I intentionally run runjs in place of npm run.
image
If you look here at run.js, you can see the code that is being unintentionally ran by npm-run-all.

I am pretty sure this problem is related to #196. The error looks to be exactly the same, and on my machine, yarn aliases to npx yarn which would cause yarn to throw an error where npm would work fine.
yarn:
image
npm:
image

Testing:

I went ahead and ran the automated tests in GH actions, and all the of the current tests look like they pass with these changes. It might make sense to introduce a test for running npm-run-all using npx, and maybe, even one for running yarn with npx.

[UPDATE]: not sure why AppVeyor tests failed (I mean, the tests didn't even run, they just crapped out before they started). The error does not seem to be related to my changes at all, so idk 🤷‍♀️ I'm looking into it, but if someone knows, I would love clarification.

Cannot find module 'C:\projects\npm-run-all\node'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
    at Function.Module._load (internal/modules/cjs/loader.js:562:25)
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! npm-run-all@4.1.5 _mocha: `mocha "test/*.js" --timeo

[2ND UPDATE]: It seems that the same error is happening in other PRs which don't even touch the code:

EX: #216 => https://ci.appveyor.com/project/mysticatea/npm-run-all/builds/41262284
This PR only touches a markdown file, so it looks like the App Veyor PR test doesn't work anymore which is not super suprising since the last commit was 3 years ago.

Additional Information

I also modified how yarn is detected because I modified npmPath (which was how yarn was being detected previously). Before, isYarn was false when npx was used in conjunction with yarn. With these changes, it should actually detect yarn even if you run yarn using npx. (EX npx yarn dev)

before:
before
after:
image

Before, `isYarn` would be false if you ran yarn using `npx`.
npm_execpath points to npx if you are
running this inside of npx
@MarmadileManteater MarmadileManteater deleted the runjs-being-called-instead-of-npm-run branch November 9, 2022 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant