Skip to content

Incorrect .js suffix added to named module import in declaration files. #60930

Closed as not planned
@MicahZoltu

Description

🔎 Search Terms

declaration js extension named module node10

🕗 Version & Regression Information

  • I was unable to test this on prior versions because I'm lazy and I suspect this bug has existed since module type node10 was introduced since it is somewhat obscure.

⏯ Playground Link

Not possible because repro requires multiple files.

💻 Code

//index.ts
import { secp256r1 } from '@noble/curves/p256'
import { apple } from './other.js'
export const noble = secp256r1
apple
// other.ts
export const apple: number = 5
{
    "compilerOptions": {
        "module": "ESNext",
        "target": "ES2024",
        "moduleResolution": "Node10",
        "emitDeclarationOnly": true,
        "declaration": true,
    }
}

🙁 Actual behavior

The generated .d.ts file has

export declare const noble: import("@noble/curves/_shortw_utils.js").CurveFnWithCreate;

but this is invalid because there is no named export of @noble/curves/_shortw_utils.js. In particular, there .js suffix should not be added.

🙂 Expected behavior

The generated .d.ts file doesn't include an extraneous .js on the dynamic import statement.

export declare const noble: import("@noble/curves/_shortw_utils").CurveFnWithCreate;

Additional information about the issue

The reason I think this is a bug and not just some esoteric behavior of node10 module resolution is that if you do not import other.js, it correctly emits the following line instead (note the missing .js extension):

export declare const noble: import("@noble/curves/_shortw_utils").CurveFnWithCreate;

Either it is correct with the .js extension (a Node10 module resolution thing), or it is correct without the .js extension, but it doesn't make sense that the presence of an extension would changed based on whether or not a local file was imported.

Note: Bug does not reproduce if you import from another package. It only seems to occur if you import from a relative path (which is why there is no playground repro).

Metadata

Assignees

No one assigned

    Labels

    Won't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions