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

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

Closed
lukastaegert opened this issue Apr 18, 2022 · 2 comments

Comments

@lukastaegert
Copy link

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.

@lightyen
Copy link
Owner

Thank you for the feedback!

@lukastaegert
Copy link
Author

Wow, this was fast, great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants