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 esm to import esm synchronously. #922

Open
jakobrosenberg opened this issue Dec 8, 2022 · 1 comment
Open

Using esm to import esm synchronously. #922

jakobrosenberg opened this issue Dec 8, 2022 · 1 comment

Comments

@jakobrosenberg
Copy link

Is it possible to do something like this with esm to synchronously import esm modules?

import esm from 'esm'
import { createRequire } from "node:module";
const require = createRequire(import.meta.url)(esm)(module);


// synchronously import a file
const thing = require('./somefile.js')
@jakobrosenberg
Copy link
Author

I found a work around by creating a .cjs file to handle the dynamic imports. Alas it struggles to import ESM files if the imported file doesn't have a .mjs extension. Setting package.json type to module in the package of the imported file seems to make no difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant