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

Using package-scripts.js in ESM context? #230

Open
ctjlewis opened this issue Jun 11, 2021 · 3 comments
Open

Using package-scripts.js in ESM context? #230

ctjlewis opened this issue Jun 11, 2021 · 3 comments

Comments

@ctjlewis
Copy link

ctjlewis commented Jun 11, 2021

Sadly, I have the great misfortune of needing to work on a codebase which uses nps, and despite the project's stated goal, "unmaintainable mess" is quite an understatement due to the number of security vulnerabilities and CJS/ESM conflicts I'm getting.

Is there any way for me to load package-scripts.js in an ESM context? It seems like nps is just trying to naively require(...) the module without checking for mjs extension, so nps -c ./package-scripts.mjs throws ERR_REQUIRE_ESM.

@brekk
Copy link

brekk commented Jun 29, 2021

@ctjlewis Have you tried using the .cjs extension? I was having the same problem but I was able to get things working by changing the package-scripts.js file to package-scripts.cjs and then calling nps with the command:

nps -c ./package-scripts.cjs

Definitely not as simple as just typing nps of course, but I aliased the above in my bash profile and that's at least a workable answer (for me).

@jcubic
Copy link

jcubic commented Jul 1, 2021

I have similar problem, also the old project that use nps. But in my case nps run other nps scripts and nps -c ./package-scripts.cjs doesn't work because nested nps are no invoked I've got error that no config get found. Only top level nps is executed.

@SupremeTechnopriest
Copy link

SupremeTechnopriest commented Aug 3, 2021

You have a few options:

  1. Use yaml instead of json package-scripts.yaml
  2. Add a .npmrc.json with the following config and rename package-scripts.js to package-scripts.cjs
{
  "config": "./package-scripts.cjs"
}

I use the .cjs option.

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

4 participants