-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Description
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
- Scaffold a Vanilla project with
npm init @vitejs/app npm install && npm install @tidyjs/tidy@2.3.0 d3-array@1.2.1- Replace
main.jswith:
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())
)
);- 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.