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

linked package's .mjs files cannot be externalized via test.server.deps.external #6554

Open
6 tasks done
hi-ogawa opened this issue Sep 24, 2024 · 0 comments
Open
6 tasks done

Comments

@hi-ogawa
Copy link
Contributor

hi-ogawa commented Sep 24, 2024

Describe the bug

For the issue #6543, I was suggesting to externalize monorepo packages, but while testing it out, I noticed .mjs outside of node_modules is currently inlined due to extraInlineDeps

export const extraInlineDeps = [
/^(?!.*node_modules).*\.mjs$/,
/^(?!.*node_modules).*\.cjs\.js$/,
// Vite client
/vite\w*\/dist\/client\/env.mjs/,
]

Since Vite-node matches options.inline before options.external, it doesn't look possible to externalize linked package's .mjs.

if (matchExternalizePattern(id, moduleDirectories, options?.inline)) {
return false
}
if (matchExternalizePattern(id, moduleDirectories, options?.external)) {
return id
}

Is there any way to achieve this? It looks like this might be desired in some case though not many. If we check options.external before options.inline, then that would allow it but not sure how breaking this change would be.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-tq3er6?file=vite.config.ts

With a package exporting linked-dep/good.js and linked-dep/bad.mjs, using test.server.deps.external: [/\/linked-dep\//] externalizes only linked-dep/good.js. Here is a log from DEBUG=vite-node:* vitest:

  vite-node:client:native /home/projects/vitest-dev-vitest-tq3er6/linked-dep/good.js +5ms
  vite-node:server:request /linked-dep/bad.mjs +24ms
  vite-node:client:execute /home/projects/vitest-dev-vitest-tq3er6/linked-dep/bad.mjs +21ms

System Info

(stackblitz)

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitest/ui: latest => 2.1.1 
    vite: latest => 5.4.7 
    vitest: latest => 2.1.1

Used Package Manager

npm

Validations

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