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

Switch from ES modules to be able to run on "npx" #29

Closed
rodrigo-picanco opened this issue Dec 26, 2021 · 1 comment
Closed

Switch from ES modules to be able to run on "npx" #29

rodrigo-picanco opened this issue Dec 26, 2021 · 1 comment

Comments

@rodrigo-picanco
Copy link

Context

Hey @sindresorhus thank you for the lib!

I was trying to use trough npx and sadly found out that the module can not be run by it since it is and ES module.

Reproducing

When I run it I get the flowing error

npx npm-name-cli @fluid

npx: installed 286 in 33.964s
Cannot use import statement outside a module
(node:3732) Warning: require() of ES modules is not supported.
require() of /home/rpt/.npm/_npx/3732/lib/node_modules/npm-name-cli/cli.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename cli.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /home/rpt/.npm/_npx/3732/lib/node_modules/npm-name-cli/package.json.

Versions

I'm using node 12.14 and npm 6.13.4 on arch and zsh to reproduce it.

I guess the module version is the latest in npx, which to me seems to be 4.0.1.

Suggestions

From the error I'm guessing it could be done by simply changing the cli file extension from .js to .cjs, but I'm not that familiar with this kind of issue.

I'm willing to help and even try to open a PR if you are open to it.

Thank again for the amazing OSS you do!

@sindresorhus
Copy link
Owner

That is a npx issue and should be opened here instead: https://github.com/npm/cli

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

No branches or pull requests

2 participants