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

ESM + Relative imports without .js extension causes "ReferenceError: require is not defined in ES module scope" #1123

Open
ctian1 opened this issue Oct 13, 2023 · 3 comments
Labels
question Further information is requested

Comments

@ctian1
Copy link

ctian1 commented Oct 13, 2023

If you have a package that uses ESM + relative imports without .js extension, ex:

export * from './utils'

ncc will think that it can't find utils and produce eval("require")("./utils"), resulting in "ReferenceError: require is not defined in ES module scope".

@styfle styfle added the question Further information is requested label Oct 13, 2023
@styfle
Copy link
Member

styfle commented Oct 13, 2023

Does it work when running your source file with node directly?

Typically you need either { "type": "module" } in package.json or rename the file to .mjs

https://nodejs.org/api/esm.html#enabling

@styfle
Copy link
Member

styfle commented Oct 13, 2023

@marcofranssen
Copy link

I'm facing the same with typescript.

See here for the failure: marcofranssen/setup-kubectl#114

For some strange reason it does still work with ncc 0.36.0.

On another project https://github.com/marcofranssen/setup-kubectl it works flawless. I have been comparing both my projects like crazy, I can't find the reason why it isn't working in one of the projects.

Tried with and without type: "module" in package.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants