Skip to content

Local and transitive dependencies resolved into different "instances" in dev mode #7708

@pr0da

Description

@pr0da

Describe the bug

Take the following dependency structure:

my-project
  - dep-a@1.0.0
  - dep-b
     - dep-a@1.0.0 

dep-a should resolve to the same "instance" whether I access it directly (import depA from 'dep-a') or indirectly via dep-b (e.g when it re-exports members from dep-a or returns a dep-a object, etc).

In dev mode this does not seem to be the case. I got back two separate "instances" from the same package, with the same version.

See the attached example where dep-a is luxon@1.28.0 and dep-b is cron-parser@4.3.0".

I think this is a regression in 2.9.0:

vite@2.9.1: example: different behaviour in prod and dev mode

  • dev mode: the DateTime instances are different (different prototype, constructor name, etc)
  • prod mode: works as expected, local and transitive code share the same DateTime instance

vite@2.8.6: example: works as expected

  • dev/prod mode: identical, local and transitive code share the same DateTime instance

Luxon resolves to the same version (yarn why luxon):

├─ cron-parser@npm:4.3.0
 │  └─ luxon@npm:1.28.0 (via npm:^1.28.0)
 │
└─ my-project@workspace:.
   └─ luxon@npm:1.28.0 (via npm:^1.28.0)

Reproduction

https://stackblitz.com/edit/vitejs-vite-n3tocb?file=package.json

System Info

System:
    OS: macOS 12.3.1
    CPU: (8) arm64 Apple M1
    Memory: 179.31 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.14.0 - ~/.nvm/versions/node/v16.14.0/bin/node
    Yarn: 3.2.0 - ~/.nvm/versions/node/v16.14.0/bin/yarn
    npm: 8.3.1 - ~/.nvm/versions/node/v16.14.0/bin/npm
  Browsers:
    Chrome: 100.0.4896.75
    Safari: 15.4
  npmPackages:
    vite: 2.9.1 => 2.9.1

Used Package Manager

yarn

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    inconsistencyInconsistency between dev & buildp2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions