Skip to content

a dep import in absolute path (with alias) isn't scanned in optimize process at first in Vite 6 #20010

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

Open
7 tasks done
Jinjiang opened this issue May 8, 2025 · 0 comments
Open
7 tasks done

Comments

@Jinjiang
Copy link
Contributor

Jinjiang commented May 8, 2025

Describe the bug

For special reasons, I have to import some packages in absolute path, like:

import '/Users/xxx/my-project/node_modules/foo/x.js'

with config:

{
  resolve: {
    alias: [{
      find: '/Users/xxx/my-project/node_modules/foo',
      replacement: 'foo',
    }]
  }
}

In both Vite 5 and Vite 6 they work as expected, however, in Vite 6, it will cause a warning message like:

5:50:59 PM [vite] (client) ✨ new dependencies optimized: foo/x.js

I understand the optimize process didn't well reorganize the absolute path import as a package one at first but somehow did it later.

Repro: https://github.com/Jinjiang/reproductions/tree/vite-deps-alias-20250507-2

Even in some cases, there will be some other "file not exist" warnings like:

5:44:27 PM [vite] (client) ✨ new dependencies optimized: foo/foo1.mjs, foo/foo-a.cjs, foo/foo-b.cjs, foo/foo-c.mjs, @mdx-js/react, bar
5:44:27 PM [vite] (client) ✨ optimized dependencies changed. reloading
The file does not exist at "/<project-root>/node_modules/.vite/deps/chunk-E6KUT42S.js?v=05fb22f8" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.

Repro: https://github.com/Jinjiang/reproductions/tree/vite-deps-alias-20250507 (sorry I can't simplify it further to keep the whole warnings on)

I'd like to understand what the difference is between Vite 5 and Vite 6, and how to avoid or skip the warning messages being printed if it's not a bug.

Thanks.

Reproduction

https://github.com/Jinjiang/reproductions/tree/vite-deps-alias-20250507-2

Steps to reproduce

How to reproduce:

pnpm install
pnpm dev

run it in VIte 5

pnpm dev:5

System Info

System:
    OS: Linux 5.15 Ubuntu 22.04.3 LTS 22.04.3 LTS (Jammy Jellyfish)
    CPU: (10) arm64 unknown
    Memory: 5.82 GB / 7.64 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 22.14.0 - ~/.volta/tools/image/node/22.14.0/bin/node
    npm: 10.9.2 - ~/.volta/tools/image/node/22.14.0/bin/npm
    pnpm: 10.9.0 - ~/.volta/bin/pnpm
  Browsers:
    Chromium: 135.0.7049.114
  npmPackages:
    @vitejs/plugin-react: ^4.4.1 => 4.4.1

Used Package Manager

pnpm

Logs

5:50:59 PM [vite] (client) ✨ new dependencies optimized: foo/foo.mjs

or:

5:44:27 PM [vite] (client) ✨ new dependencies optimized: foo/foo1.mjs, foo/foo-a.cjs, foo/foo-b.cjs, foo/foo-c.mjs, @mdx-js/react, bar
5:44:27 PM [vite] (client) ✨ optimized dependencies changed. reloading
The file does not exist at "/<project-root>/node_modules/.vite/deps/chunk-E6KUT42S.js?v=05fb22f8" which is in the optimize deps directory. The dependency might be incompatible with the dep optimizer. Try adding it to `optimizeDeps.exclude`.

Validations

@Jinjiang Jinjiang changed the title a dep in absolute path (with alias) isn't scanned in optimize process in Vite 6 a dep import in absolute path (with alias) isn't scanned in optimize process in Vite 6 May 8, 2025
@Jinjiang Jinjiang changed the title a dep import in absolute path (with alias) isn't scanned in optimize process in Vite 6 a dep import in absolute path (with alias) isn't scanned in optimize process at first in Vite 6 May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant