vitest
vitest copied to clipboard
Dependencies are not inlined when using ssr.noExternal with globs
Describe the bug
The docs state that anything in the ssr.noExternal array in the Vite config is automatically added to the test.server.deps.inline array.
Globs do not seem to be supported.
Repo: https://github.com/eduardoRoth/analog-ionic-capacitor-template
Reproduction
- Clone the repo - https://github.com/eduardoRoth/analog-ionic-capacitor-template
- Install the dependencies -
npm i - Go into the vite.config.ts
- Remove
@ionic/angularfrom thetest.server.deps.inlinearray.@ionic/**is already in thessr.noExternalarray. - Run
npx ng test - Note the error, stop the tests
- Go into the
ssr.noExternalarray - Add
@ionic/angular - Run
npx ng test - Note the tests pass
System Info
System:
OS: macOS 12.6.8
CPU: (10) arm64 Apple M1 Pro
Memory: 231.17 MB / 32.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.19.1 - ~/.nvm/versions/node/v18.19.1/bin/node
Yarn: 1.22.15 - ~/.yarn/bin/yarn
npm: 10.2.4 - ~/.nvm/versions/node/v18.19.1/bin/npm
pnpm: 9.3.0 - ~/Library/pnpm/pnpm
bun: 1.0.35 - ~/.bun/bin/bun
Browsers:
Chrome: 126.0.6478.61
Safari: 15.6.1
npmPackages:
vite: ~5.2.11 => 5.2.13
vitest: ^1.3.1 => 1.6.0
Used Package Manager
npm
Validations
- [X] Follow our Code of Conduct
- [X] Read the Contributing Guidelines.
- [X] Read the docs.
- [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [X] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [X] The provided reproduction is a minimal reproducible example of the bug.
Indeed, glob doesn't seem to be supported for server.deps.inline.
Vite uses createFilter utility https://github.com/vitejs/vite/blob/ec16a5efc04d8ab50301d184c20e7bd0c8d8f6a2/packages/vite/src/node/ssr/ssrExternal.ts#L38-L41 to support glob, but Vitest (vite-node) has a different logic to match patterns
https://github.com/vitest-dev/vitest/blob/f969fb0f9f0247a7daa2afee8f70de25ea5e123f/packages/vite-node/src/externalize.ts#L157-L162
I created a repro with simpler dependencies https://github.com/hi-ogawa/reproductions/tree/main/vitest-5911-deps-inline-glob
Thanks @hi-ogawa. I can work on a PR to support this behavior if that's whats recommended
vite-node processes ssr.noExternal on resolved file paths, Vite processes it on bare imports, so we cannot apply the same filter.
vite-node processes
ssr.noExternalon resolved file paths, Vite processes it on bare imports, so we cannot apply the same filter.
Ok. What would be the recommended approach with globs?
Ok. What would be the recommended approach with globs?
If I knew what to do with this, we would've already implemented it 😞
I don't know how to solve these, they were always resolved differently in Vite and Vitest. Vite can also resolve monorepo packages while Vitest expects that the package is in moduleDirectories and the name and the folder are the same.
If it's fine to keep this difference, we can just apply the glob with the same rule - svelte/* will be equal to node_modules/svelte/.+
Thanks @sheremet-va. I think it's fine to keep this difference, and note that globs are not expected to be inlined also
Vitest 4 actually supports globs by turning them to regexp.