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 compatibility for native plugins #14

Closed
ClementValot opened this issue Jul 25, 2022 · 2 comments
Closed

ESM compatibility for native plugins #14

ClementValot opened this issue Jul 25, 2022 · 2 comments

Comments

@ClementValot
Copy link

When bundling with rollup and exporting ESM code (rollupConfig.output.format == 'es'), the rollup-plugin-natives outputs .node dependencies as require: var cpufeatures = require("./cpufeatures.node"); which causes ReferenceError: require is not defined in ES module scope, you can use import instead at runtime.

Additionally, node ESM doesn't support ".node" imports natively (see nodejs/node#40541 )

Workaround I used is appending import { createRequire } from 'module'; const require = createRequire(import.meta.url); at the top of the bundle file.

Something similar could be implemented in the meantime until ESM actually supports native imports

@danielgindi
Copy link
Owner

This would have to be a flag in the module options, to specify that you are exporting as ESM.
Do you want to make a PR?

@danielgindi
Copy link
Owner

Supported in 0.7.6

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