Skip to content

[Vite 8] Error when importing package with $ symbol #22198

@RSWilli

Description

@RSWilli

Describe the bug

Related to #21885

We maintain an internal npm package that uses $ as part of the import paths. In Vite 7 this works fine.

After vite dev in Vite 8 I get the following error:

[optimizer] bundling dependencies...
file:///home/willi/work/xstream/xstream-development-workspace/xstream/www/node_modules/vite/dist/node/chunks/node.js:31468
                                        const { exportsData, file, id, ...info } = depForEntryFileName[chunk.fileName];
                                                ^

TypeError: Error during dependency optimization:

Cannot destructure property 'exportsData' of 'depForEntryFileName[chunk.fileName]' as it is undefined.
    at file:///home/willi/work/xstream/xstream-development-workspace/xstream/www/node_modules/vite/dist/node/chunks/node.js:31468:14

P.S: I figured out that the cause is the import with the $ because I changed the node.js file to throw a more specific error:

					const dep = depForEntryFileName[chunk.fileName];
					
					if (!dep) {
						throw new Error(`Internal error: could not find dep info for entry chunk with fileName ${chunk.fileName}`);
					}

					const { exportsData, file, id, ...info } = dep;

I think that something like this could help users find these issues easier.

Reproduction

https://stackblitz.com/edit/vitejs-vite-ymrh2f2d?file=src%2Fcounter.js

Steps to reproduce

  • Use stackblitz Link above.
  • Run npm run install and npm run dev.
  • The above log is immediatly printed to console and vite exits

System Info

System:
    OS: Linux 6.19 cpe:/o:nixos:nixos:26.05 26.05 (Yarara)
    CPU: (16) x64 AMD Ryzen AI 7 PRO 350 w/ Radeon 860M
    Memory: 9.86 GB / 30.53 GB
    Container: Yes
    Shell: 5.9 - /run/current-system/sw/bin/zsh
  Binaries:
    Node: 24.14.0 - /nix/store/v2210ar51jddnrcx46m53ivv9palc26m-nodejs-24.14.0/bin/node
    npm: 11.9.0 - /nix/store/v2210ar51jddnrcx46m53ivv9palc26m-nodejs-24.14.0/bin/npm
  Browsers:
    Chromium: 146.0.7680.177
    Firefox: 149.0
    Firefox Developer Edition: 149.0
  npmPackages:
    vite: ^8.0.0 => 8.0.7

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: deps optimizerEsbuild Dependencies Optimizationp2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions