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

Vite resolves import with browser field during SSR #2995

Closed
6 tasks done
benmccann opened this issue Apr 15, 2021 · 2 comments · Fixed by #2996
Closed
6 tasks done

Vite resolves import with browser field during SSR #2995

benmccann opened this issue Apr 15, 2021 · 2 comments · Fixed by #2996
Labels
feat: ssr p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)

Comments

@benmccann
Copy link
Collaborator

Describe the bug

The presence of a browser field is causing Vite to try to load the client-side version of an isomorphic package on the server-side.

Reproduction

npm init svelte@next
npm install
npm install websocket
sed -i "s/<script>/<script>\n\timport { w3cwebsocket } from 'websocket';\n\tconsole.log(w3cwebsocket);\n/" ./src/routes/index.svelte
npm run dev

System Info

Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers:

  System:
    OS: Linux 5.8 Ubuntu 20.04.2 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
    Memory: 17.36 GB / 31.14 GB
    Container: Yes
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.16.0 - ~/.nvm/versions/node/v14.16.0/bin/node
    npm: 7.9.0 - ~/.nvm/versions/node/v14.16.0/bin/npm
  Browsers:
    Chrome: 89.0.4389.114
    Firefox: 87.0
  npmPackages:
    vite: ^2.1.0 => 2.1.5

Used package manager: npm

Logs

3:26:21 PM [vite] Error when evaluating SSR module /node_modules/websocket/lib/browser.js?v=364f06a3:
ReferenceError: require is not defined
    at /node_modules/websocket/lib/browser.js?v=364f06a3:15:25

Before submitting the issue, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the docs.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Provide a description in this issue that describes the bug.
  • Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
  • Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
@stupidawesome
Copy link

Can this issue be reopened? The mentioned PR doesn't completely resolve this issue.

See related: supabase/supabase-js#154 (comment)

@GrygrFlzr
Copy link
Member

@stupidawesome Looking at your linked comment, it looks like that should be opened as a new issue instead, because the root of that issue seems to be Vite only resolving dependencies once + incorrectly resolving isomorphic packages, whereas this seems to be only concerned with the browser field in package.json.

@github-actions github-actions bot locked and limited conversation to collaborators Jul 16, 2021
@benmccann benmccann added bug p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) feat: ssr and removed pending triage labels Aug 18, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: ssr p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants