Skip to content

plugin-typescript 12.1.3 cannot find modules with custom resolution logic #1877

Open
@SquidDev

Description

@SquidDev

Expected Behavior

On plugin-typescript 12.1.2 and below, it was possible to use a plugin with resolveId and declare module "xyz" { ... } to load modules outside the standard resolution path (for instance, loading generated sources from elsewhere).

For instance, with the following in your rollup.config.js.

    plugins: [
        typescript(),
        {
            name: "custom",
            async resolveId(source) {
                if (source === "test-module") return path.resolve("generated/test-module.js")
            }
        }
    ]

and the following declaration file:

declare module "test-module" {
    export const sayHello: () => void;
}

Then it was possible to import "test-module" from a Typescript file.

Actual Behavior

This no longer works under the recent 12.1.3 release (I assume this is introduced by #1653), failing with the following:

(!) [plugin typescript] src/index.ts (1:26): @rollup/plugin-typescript TS2307: Cannot find module 'test-module' or its corresponding type declarations.
rollup-demo/src/index.ts:1:26

1 import { sayHello } from "test-module";
                           ~~~~~~~~~~~~~

Additional Information

It's possible I'm doing something utterly unspeakable and unsupported! I wasn't sure if this was an accidental breaking change or just Hyrum's law in action, so felt worth reporting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions