New problem kind: cjs-module-lexer incompatibility
andrewbranch opened this issue · comments
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.
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.