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

[BUG] npx . launches bin script in shell #7201

Closed
2 tasks done
PRR24 opened this issue Feb 5, 2024 · 8 comments
Closed
2 tasks done

[BUG] npx . launches bin script in shell #7201

PRR24 opened this issue Feb 5, 2024 · 8 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x

Comments

@PRR24
Copy link

PRR24 commented Feb 5, 2024

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

Launching npx . within module executes script defined in package.json/bin in shell.

Expected Behavior

Script is executed with node.
It was executed with node in older versions of the npm.

Steps To Reproduce

  1. npm init
  2. index.js: console.log("test");
  3. package.json: "bin": "./index.js"
  4. npm install
  5. npx .
  6. shell error about console log is displayed (varies from one platfrom to another)

Environment

  • npm: 10.2.4
  • Node.js: 21
  • OS Name: Ubuntu 22.04, Windows 10
  • npm config: all commented out
@PRR24 PRR24 added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels Feb 5, 2024
@ljharb
Copy link
Contributor

ljharb commented Feb 5, 2024

I’m confused; executing it with node would be up to the shebang in the file referenced by the build script.

@ljharb
Copy link
Contributor

ljharb commented Feb 5, 2024

What does which node say?

@PRR24
Copy link
Author

PRR24 commented Feb 5, 2024

/usr/bin/node on Linux and
/usr/local/bin/node on Mac
The index.js file contains only single line of code (above) and node index.js works as expected.

@ljharb
Copy link
Contributor

ljharb commented Feb 5, 2024

Ahh. When a package like that is installed, npm creates the appropriate infra required to make it runnable directly, but that wouldn’t be present in the current package.

In which version of npm/npx did this work?

@PRR24
Copy link
Author

PRR24 commented Feb 5, 2024

Works perfectly with npx 6.14.16 / node 14.19.1
Found this issue while upgrading old machine, but couldn't find any notice about the change or a new way to execute node project locally.
Goal is to:

  • git clone
  • npm install
  • [insert command here that is not node somedirectory/subdirectory/app.js, previously npx .]

npm start -- --argument value is the best alternative I have found so far, but it is more error prone for users to write (especially the -- in the middle)

It would be great if npm could detech local usage and support it. I think it would also be reasonable to skip caching the local project.

@PRR24
Copy link
Author

PRR24 commented Feb 5, 2024

One more thing... The package is being copied to ~/.npm/, as a result of executing npx . so it is kind'a getting installed, just from local source, not from npm repo.

@milaninfy
Copy link
Contributor

@PRR24 I think you should have #!/usr/bin/env node in your code file as first line if you are expecting it to be run with node.

@milaninfy
Copy link
Contributor

Closing due to age. If this is still a problem please feel free to reopen this issue, or create a new issue w/ steps to reproduce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x
Projects
None yet
Development

No branches or pull requests

3 participants