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

fix: resolve nested dependencies (#3254) #3753

Merged
merged 5 commits into from
Jun 27, 2021
Merged

fix: resolve nested dependencies (#3254) #3753

merged 5 commits into from
Jun 27, 2021

Conversation

Yelmor
Copy link
Contributor

@Yelmor Yelmor commented Jun 10, 2021

Description

Current vite(2.3.7) cannot resolve nested package on dev mode.

If a project has dependencies like this:

.
└── node_modules
    ├── package-a@2.0.0
    │   └── package.json
    └── package-b@1.0.0
        ├── node_modules
        │   └── pacakge-a@1.0.0
        │       └── package.json
        └── package.json

Only package-a@2.0.0 will be load at runtime, and package-b actually import package-a@2.0.0 instead of package-a@1.0.0 .

Additional context

There was two fixes before.

#3003 uses resolveDir as module location, which worked. But it mistakenly use flatId as module path, causing scoped package cannot be resolved.

#3053 changed flatId to qualified[flatId], which fixed scoped package problem, but again the nested pacakge problem occurs.

I'm not sure if this commit finnally fix the problem, or causing further errors, it passed the tests anyway.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

yarn.lock Outdated Show resolved Hide resolved
@Shinigami92 Shinigami92 added the p3-minor-bug An edge case that only affects very specific usage (priority) label Jun 10, 2021
@Yelmor Yelmor requested a review from Shinigami92 June 26, 2021 07:13
@Yelmor
Copy link
Contributor Author

Yelmor commented Jun 27, 2021

Awesome! So this fix can be merged now?

@patak-dev
Copy link
Member

@Yelmor would you check #4005? Looks like react-query devtools are breaking after this PR. If it is not something easy to solve, maybe we should revert this one for 2.4.0 and keep iterating on it

@Yelmor
Copy link
Contributor Author

Yelmor commented Jun 29, 2021

@Yelmor would you check #4005? Looks like react-query devtools are breaking after this PR. If it is not something easy to solve, maybe we should revert this one for 2.4.0 and keep iterating on it

I checked the demo and find out that the dependency react-query should resolve to /node_modules/react-query/es/index.js but the nodejs require.resolve resolves it to /node_modules/react-query/lib/index.js.

And I checked the code, vite has it's own way to resolve deps, it creates PluginContainer and uses plugins to do that.

So using single require.resolve is not the correct way to fix the problem.

It seems not easy to extract a independent funciton to resolve sub-deps path from deps directory in vite's way.

You may revert this fix for current release, but we still need to find a way to fix the problem.

@patak-dev
Copy link
Member

Thanks for looking into this. It seems there are two other related issues #4014 and #4012. I think we should revert and keep working on a solution

patak-dev added a commit that referenced this pull request Jun 29, 2021
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
* fix: resolve nested dependencies (vitejs#3254)

* chore: inline packages

* chore: force optimize

* chore: cleanup

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
aleclarson pushed a commit to aleclarson/vite that referenced this pull request Nov 8, 2021
@dickeylth
Copy link
Contributor

Thanks for looking into this. It seems there are two other related issues #4014 and #4012. I think we should revert and keep working on a solution

The issue still exists vite@2.7.12, and #4014 and #4012 are closed, is there anyone still working on the issue?

@patak-dev
Copy link
Member

@dickeylth would you create a new issue against the latest version of vite (vite@2.8.0-beta.3) so we can properly track the bug report?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants