fix(resolve): normalize node_modules and bare imports, fix #2503#2848
Merged
patak-cat merged 4 commits intovitejs:mainfrom May 4, 2021
patak-cat:fix/2503
Merged
fix(resolve): normalize node_modules and bare imports, fix #2503#2848patak-cat merged 4 commits intovitejs:mainfrom patak-cat:fix/2503
patak-cat merged 4 commits intovitejs:mainfrom
patak-cat:fix/2503
Conversation
meteorlxy
reviewed
Apr 4, 2021
Comment on lines
+127
to
+128
| const pathFromBasedir = normalizePath(fsPath).slice(basedir.length) | ||
| if (pathFromBasedir.startsWith('/node_modules/')) { |
Contributor
There was a problem hiding this comment.
Not sure if this will work in monorepo case?
Member
Author
There was a problem hiding this comment.
Do you have a failing repro after this PR?
I think one possible improvement is to trigger the node resolution at this point, but only use it if the resolved path is the same one as the one being imported
Member
Author
There was a problem hiding this comment.
I pushed this change, it should avoid direct imports to be interpreted as packages from other node_modules folders.
antfu
previously approved these changes
May 4, 2021
antfu
previously approved these changes
May 4, 2021
Shinigami92
approved these changes
May 4, 2021
fi3ework
pushed a commit
to fi3ework/vite
that referenced
this pull request
May 22, 2021
vitejs#2848) Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
7 tasks
9 tasks
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…
Description
Fix for #2503, the issue is explained in detail there.
Direct link to the reproduction https://github.com/meteorlxy/repro-vite-2503
Additional context
It is not that easy to add this to the tests. I think it would be great if something similar is added later to the repro (maybe also using
cpx2)@meteorlxy suggested that a possible solution is to inject version hash according to the node_modules path prefix, instead of only injecting for bare imports.
Given the current structure of the Resolve plugin, and that hashes are not the only special logic (we also have
dedupe, we need to deal with pre-bundled deps). This PR normalizes direct node_modules imports to bare imports, so the same logic is applied in both cases. There may be a better way to do this, but I think it would involve a big refactoring. This PR not only fixes #2503, but probably other issues with direct node_modules import, for example its interaction withdedupeWhat is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).