Skip to content
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

Dependencies are not inlined when using ssr.noExternal with globs #5911

Open
6 tasks done
brandonroberts opened this issue Jun 17, 2024 · 6 comments
Open
6 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) vite-node

Comments

@brandonroberts
Copy link

brandonroberts commented Jun 17, 2024

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

  1. Clone the repo - https://github.com/eduardoRoth/analog-ionic-capacitor-template
  2. Install the dependencies - npm i
  3. Go into the vite.config.ts
  4. Remove @ionic/angular from the test.server.deps.inline array. @ionic/** is already in the ssr.noExternal array.
  5. Run npx ng test
  6. Note the error, stop the tests
  7. Go into the ssr.noExternal array
  8. Add @ionic/angular
  9. Run npx ng test
  10. 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

@hi-ogawa
Copy link
Contributor

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

for (const ex of patterns) {
if (typeof ex === 'string') {
if (moduleDirectories.some(dir => id.includes(join(dir, ex)))) {
return true
}
}

I created a repro with simpler dependencies https://github.com/hi-ogawa/reproductions/tree/main/vitest-5911-deps-inline-glob

@hi-ogawa hi-ogawa added vite-node p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Jun 18, 2024
@brandonroberts
Copy link
Author

Thanks @hi-ogawa. I can work on a PR to support this behavior if that's whats recommended

@sheremet-va
Copy link
Member

vite-node processes ssr.noExternal on resolved file paths, Vite processes it on bare imports, so we cannot apply the same filter.

@brandonroberts
Copy link
Author

vite-node processes ssr.noExternal on 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?

@sheremet-va
Copy link
Member

sheremet-va commented Jun 23, 2024

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/.+

@brandonroberts
Copy link
Author

Thanks @sheremet-va. I think it's fine to keep this difference, and note that globs are not expected to be inlined also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p3-minor-bug An edge case that only affects very specific usage (priority) vite-node
Projects
None yet
Development

No branches or pull requests

3 participants