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
fix(node-resolve): Fix bug where JS import was converted to a TS import, resulting in an error when using export maps #921
fix(node-resolve): Fix bug where JS import was converted to a TS import, resulting in an error when using export maps #921
Conversation
so that other candidates in `importSpecifierList` can be tried
Just to clarify I'm understanding the logic here, this PR will:
Would help to get a clear sense of it. |
I don't think so. If a package uses Previously the loop would continue for the non exports resolver (which did return
Before this PR this is already the case for the normal resolver, and think it should also be the case for when the export map resolver is used? So that the behaviour is the same, I'm still not sure why we do the convert
Not sure what you mean by this one? |
This is the thing that's the issue here - "exports" is designed to be an authoritative resolution system. If the file is not found it should not resolve, only unless it is a "require" resolution in which case CommonJS extension searching can apply. For ES module resolutions exports should include the final file extension always.
The issue is what if the exports mapping is like |
Hmm ok. In which case maybe we should scrap the I also think the priority order is wrong and we should be doing importSpecifierList.push(importee); before we push the one with the extension switch and the directory version. |
Agreed this should not be happening. |
Cool. I'll update this then so that for export maps we don't loop through |
@guybedford we still loop through other options on a |
…op priority and with a later commit will be the only one that export maps are tried on
…gorithm and to try the exports algorithm first, and only with the first id
mixup from having multiple branches
// first try to look up a local module with that name. If we don't | ||
// find anything, we resolve the builtin which just returns back | ||
// the built-in's name. | ||
importSpecifierList.push(`${importee}/`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass without this now, so I think maybe this is no longer needed since the other work I did to add includeCoreModules: false
to resolve
This reverts commit 7730f36.
c33e948
to
1ae22f4
Compare
Thanks for working on this! I look forward to it! |
486cc69
to
34ba4ce
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much @tjenkinson for your work on this PR, it is really valued. Sorry I dropped the ball on this for a while will aim to be more responsive.
I've shared some more questions mostly, if you can perhaps let me know where things stand on those hopefully we can resolve them fairly quickly, also deciding which are in and out of scope for this PR as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your PR title doesn't match the required format. The title should be in the conventional commit (https://www.conventionalcommits.org/en/v1.0.0-beta.4/) format. e.g.
chore(plugin-name): add pr title workflow
Awesome thanks for the review! Nice to see it got automatically published now too great work on that @shellscape |
Rollup Plugin Name:
node-resolve
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers: fixes #911, fixes #853
Description
Currently if when using export maps we resolve to a file that does not exist we don't try the remaining options. This fixes that.
We now always make the import the user wrote the first candidate, and we also only try the exports algorithm on the first candidate, and fallback to the standard node resolve algorithm for all the candidates only if the first one determines that exports are not configured.
It's specifically a problem when importing a
.js
file from a.ts
file when you have.ts
extensions configured, because for reasons I don't fully understand we first rewrite*.js
imports to*.ts
imports. Typescript itself added a 'feature' to do this, so we followed them.I think it's somehow related to js modules requiring ids to end in '*.js', but not sure why typescript decided from that to allow .js and convert .ts