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

Module * has been externalized warnings #12975

Closed
7 tasks done
edikdeisling opened this issue Apr 24, 2023 · 4 comments
Closed
7 tasks done

Module * has been externalized warnings #12975

edikdeisling opened this issue Apr 24, 2023 · 4 comments

Comments

@edikdeisling
Copy link
Contributor

Describe the bug

Starting from Vite 4.3 during build there are warnings about externalization.

Module "os" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-wogwpc/node_modules/.pnpm/jsdom@20.0.3/node_modules/jsdom/lib/jsdom/living/navigator/NavigatorConcurrentHardware-impl.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "net" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-wogwpc/node_modules/.pnpm/http-proxy-agent@5.0.0/node_modules/http-proxy-agent/dist/agent.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "tls" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-wogwpc/node_modules/.pnpm/http-proxy-agent@5.0.0/node_modules/http-proxy-agent/dist/agent.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "url" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-wogwpc/node_modules/.pnpm/http-proxy-agent@5.0.0/node_modules/http-proxy-agent/dist/agent.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "net" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-wogwpc/node_modules/.pnpm/https-proxy-agent@5.0.1/node_modules/https-proxy-agent/dist/agent.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "tls" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-wogwpc/node_modules/.pnpm/https-proxy-agent@5.0.1/node_modules/https-proxy-agent/dist/agent.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "url" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-wogwpc/node_modules/.pnpm/https-proxy-agent@5.0.1/node_modules/https-proxy-agent/dist/agent.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
[plugin:vite:resolve] Module "assert" has been externalized for browser compatibility, imported by "/home/projects/vitejs-vite-wogwpc/node_modules/.pnpm/https-proxy-agent@5.0.1/node_modules/https-proxy-agent/dist/agent.js". See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.

Seems that this is related to #12888. But that issue is closed but warnings still present

Reproduction

https://stackblitz.com/edit/vitejs-vite-wogwpc

Steps to reproduce

Open stackblitz and run pnpm build

System Info

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: 16.14.2 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 7.17.0 - /usr/local/bin/npm
  npmPackages:
    vite: 4.3.1 => 4.3.1

Used Package Manager

pnpm

Logs

No response

Validations

@stackblitz
Copy link

stackblitz bot commented Apr 24, 2023

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

@chaxus
Copy link
Contributor

chaxus commented Apr 25, 2023

The reason may be that vite cannot build the node module,The source code in packages/vite/src/node/plugins/resolve.ts is as follows:

if (id.startsWith(browserExternalId)) {
if (isProduction) {
return export default {}

It turns the node module into an empty module
It is also stated in the documentation provided,(https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility).

This is because Vite does not automatically polyfill Node.js modules.
We recommend avoiding Node.js modules for browser code to reduce the bundle size, although you can add polyfills manually. If the module is imported from a third-party library (that's meant to be used in the browser), it's advised to report the issue to the respective library.

@edikdeisling
Copy link
Contributor Author

But there are no node.js modules in the client bundle. Here is the code

const win = import.meta.env.SSR ? new (await import('jsdom')).JSDOM('').window : window;

jsdom isn't included in the final client bundle.
image

@sapphi-red
Copy link
Member

Duplicate of #5676

@sapphi-red sapphi-red marked this as a duplicate of #5676 Apr 25, 2023
@sapphi-red sapphi-red closed this as not planned Won't fix, can't repro, duplicate, stale Apr 25, 2023
@github-actions github-actions bot locked and limited conversation to collaborators May 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants