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

Two different versions of a dependency (direct + transitive) breaks dev build #3254

Closed
veltman opened this issue May 4, 2021 · 5 comments
Closed

Comments

@veltman
Copy link

@veltman veltman commented May 4, 2021

It appears that if you have two different versions of a package in your dependency tree and a file that uses both versions (one directly, one indirectly), then the dev build will resolve all references using a single version during prebundling, instead of using the locally correct version for each bundle.

I didn't see any config options that would address this, let me know if I'm missing something obvious!

Steps to reproduce

  1. Scaffold a Vanilla project with npm init @vitejs/app
  2. npm install && npm install @tidyjs/tidy@2.3.0 d3-array@1.2.1
  3. Replace main.js with:
import { min } from "d3-array";
import { tidy, groupBy } from "@tidyjs/tidy";

console.log(min([1, 2, 3]));
console.log(
  tidy(
    [1, 2, 3],
    groupBy(d => d % 2, [], groupBy.entries())
  )
);
  1. Run npm run dev

More info

In this case your package.json has:

"dependencies": {
  "@tidyjs/tidy": "2.3.0",
  "d3-array": "1.2.1"
}

So you end up with the installed dependencies:

├─┬ @tidyjs/tidy@2.3.0
│ ├─┬ d3-array@2.12.1
├── d3-array@1.2.1

When your main.js contains something like:

import { min } from "d3-array";
import { tidy, groupBy } from "@tidyjs/tidy";

then npm run dev will produce errors when trying to prebundle tidy:

> node_modules/@tidyjs/tidy/dist/es/groupBy.js:1:9: error: No matching export in "node_modules/d3-array/src/index.js" for import "group"
    1 │ import { group } from 'd3-array';

This is seemingly because it's using the direct dependency version of d3-array (d3-array@1.2.1) instead of the version that tidy depends on (d3-array^2.9.1), even though both are installed.

In this case the failure is obvious because the exported API of d3-array changes in v2, but this could also fail more insidiously since two different versions could have the same named exports but different internal behavior, so then the difference would only show up at runtime.

Note: I couldn't reproduce this same issue using esbuild directly, so the issue seems specific to the way in which vite is using it.

@Sociosarbis
Copy link
Contributor

@Sociosarbis Sociosarbis commented May 10, 2021

#3053 PR also causes the same regression bug as #3003 . @nihalgonsalves

@veltman
Copy link
Author

@veltman veltman commented May 11, 2021

Confirmed that this bug is still present in 2.3.0.

patak-js pushed a commit that referenced this issue Jun 27, 2021
* fix: resolve nested dependencies (#3254)

* chore: inline packages

* chore: force optimize

* chore: cleanup

Co-authored-by: Anthony Fu <anthonyfu117@hotmail.com>
@asfktz
Copy link

@asfktz asfktz commented Jun 28, 2021

Also present in 2.3.8

@veltman
Copy link
Author

@veltman veltman commented Jun 30, 2021

@patak-js can you clarify why this was closed? From my read of the two PRs (#3753 and #4019) it seems like a fix was tried but then reverted.

@patak-js
Copy link
Member

@patak-js patak-js commented Jun 30, 2021

Thanks @veltman, looks like GitHub interpreted from the description that this should be closed. As you said, a fix had to be reverted because of regressions. Another solution is required here.

@patak-js patak-js reopened this Jun 30, 2021
patak-js pushed a commit that referenced this issue Jul 14, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Jul 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

4 participants