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 typesFile with ESM/moduleResolution nodenext causes build error due to missing ".js" extension #163

Open
joshleitzel opened this issue Jun 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@joshleitzel
Copy link

When using the config.typesFile option in a TypeScript project with moduleResolution set to node16 or nodenext, this package will always cause an error when building the project. This is because TypeScript expects local imports to have a .js extension. For example this config:

config: {
  typesFile: "types/generated"
}

will generate an import like this:

import { Type1, Type2 } from "types/generated";

which will in turn result in the error:

Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean 'types/generated.js'?

And you can't work around it by appending the .js yourself:

config: {
  typesFile: "types/generated.js"
}

because the extension is explicitly stripped.

I'm not sure what the permanent solution here is, but I suspect the higher-level config's emitLegacyCommonJSImports value should be respected.

I worked around this for now by patch-packaging the source code to remove the extension stripping.

@ardeois
Copy link
Owner

ardeois commented Jun 10, 2024

Yes you're right we should probably add support for emitLegacyCommonJSImports option

Feel free to open a PR

@ardeois ardeois added the bug Something isn't working label Jun 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants