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

veltman opened this issue May 4, 2021 · 5 comments · Fixed by #4019 or #4091

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

veltman opened this issue May 4, 2021 · 5 comments · Fixed by #4019 or #4091


Copy link

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]));
    [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.

Copy link

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

Copy link

veltman commented May 11, 2021

Confirmed that this bug is still present in 2.3.0.

patak-dev 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 <>
Copy link

asfktz commented Jun 28, 2021

Also present in 2.3.8

Copy link

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.

Copy link

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
None yet
4 participants