Skip to content

rollup-plugin-tsconfig-paths: Pass along resolve options in resolveId hook #3

Closed
@lukastaegert

Description

@lukastaegert

Hi!

While debugging rollup/plugins#1038 (comment), I stumbled upon an issue with your rollup plugin implementation. Basically you are doing this:

async resolveId(request: string, importer?: string) {
  // ...
  if (!moduleName) {
    return this.resolve(request, importer, { skipSelf: true })
  }
  // ...
}

Unfortunately, there is a third parameter to resolveId that @rollup/plugin-node-resolve (and @rollup/plugin-commonjs) depends upon, which you do not pass along. It is encodes whether we are resolving an entry point and additional custom plugin options which for the node-resolve plugin encode if we are resolving an import or a require. Depending on the package, this can lead to different (and wrong) resolutions.

See https://rollupjs.org/guide/en/#resolveid including the first example there, as well as https://rollupjs.org/guide/en/#custom-resolver-options for how custom options work, and why it is important for plugins to forward them.

The solution can be as simple as

async resolveId(request: string, importer: string | undefined, options: {isEntry: boolean, custom?: {[plugin: string]: any}) {
  // ...
  if (!moduleName) {
    return this.resolve(request, importer, { skipSelf: true, ...options })
  }
  // ...
}

I would strongly advise to update your implementation to support this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions