Skip to content

Using typesFile with ESM/moduleResolution nodenext causes build error due to missing ".js" extension #163

Open
@joshleitzel

Description

@joshleitzel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions