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

New problem kind: cjs-module-lexer incompatibility #35

Open
andrewbranch opened this issue Jun 20, 2023 · 1 comment
Open

New problem kind: cjs-module-lexer incompatibility #35

andrewbranch opened this issue Jun 20, 2023 · 1 comment
Labels
feature New feature or request planned I'm going to do this

Comments

@andrewbranch
Copy link
Collaborator

When node16-esm resolves to a CJS module with types, we should run https://github.com/nodejs/cjs-module-lexer on it and compare the named exports visible to Node with the ones visible to TypeScript, and error for any that TS says are available that wouldn’t work in Node.

@andrewbranch andrewbranch added feature New feature or request planned I'm going to do this labels Jun 20, 2023
@laverdet
Copy link
Contributor

This isn't specific to CommonJS, since ESM types can also lie about their exports. In that case it would be a matter of parsing the source texts with esbuild and following the ESM linker specification which isn't terribly complicated.

I did some tinkering on this over here -- laverdet@c445010

I struggled a bit extracting the expected runtime exported names from typescript's API since I'm not super familiar with it. My simple implementation fails to differentiate between type-only exports and real exports. If you could point out how to extract that information then I could contribute an implementation which can statically determine the result of Object.keys(await import(moduleName)) under nodejs. With those pieces in place it would just be a matter of a flat diff between the two array of export names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request planned I'm going to do this
Projects
None yet
Development

No branches or pull requests

2 participants