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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

import("module")).default is undefined #71

Closed
jgoux opened this issue Apr 4, 2024 · 3 comments
Closed

import("module")).default is undefined #71

jgoux opened this issue Apr 4, 2024 · 3 comments

Comments

@jgoux
Copy link

jgoux commented Apr 4, 2024

Hello 馃憢,

I'm experimenting with pglite for an upcoming adapter for @snaplet/seed.

I'm not exactly sure why, but default is undefined when it hits this line:

require = (await import("module")).default.createRequire(import.meta.url);

My setup is quite complicated as I define the PGlite() connection within a TypeScript configuration file loaded through https://github.com/unjs/c12 馃槄

But everything seems to work if I remove default and directly consume createRequire like this:

require = (await import("module")).createRequire(import.meta.url);

Do you think it would be possible to have a fallback so it works in both cases:

const module = await import("module")
const createRequire = module.default?.createRequire ?? module.createRequire
require = createRequire(import.meta.url);
@samwillis
Copy link
Collaborator

Yep, I'm happy to make that change. I've seen similar things before although of the top of my head I'm not sure what triggers it (I tempted to blame CJS vs EMS...)

samwillis added a commit that referenced this issue Apr 5, 2024
@jgoux
Copy link
Author

jgoux commented Apr 5, 2024

I tempted to blame CJS vs EMS...

It's always CJS vs ESM. 馃ゲ

@samwillis
Copy link
Collaborator

Fixed in v0.1.2

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