Vite fails to load browser field from engine.io-client when using yarn berry pnp
See original GitHub issue⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.
- Read the docs.
- Use Vite >=2.0. (1.x is no longer supported)
- If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.
Describe the bug
When using yarn berry
in pnp
mode, Vite fails to properly load the package.json browser
field from engine.io-client
. This results in browser polyfills not loading.
Reproduction
- Initialize a new yarn berry repo
yarn create @vitejs/app
- Select preset
vue-ts
cd
into projectyarn add engine.io-client
- In
src/main.ts
add the following linesimport client from 'socket.io-client'; client
yarn dev
Load the site in the browser and open the console. You will see an error.
If you add nodeLinker: node-modules
to the .yarnrc.yml
file, the browser field detection works properly any you will not see errors.
System Info
vite
version:2.0.0-beta.67
- Operating System: Pop!_OS 20.04
- Node version: 14.15.4
- Package manager (npm/yarn/pnpm) and version:
yarn 2.4.0
P.S. I understand that yarn pnp
is sometimes difficult to work with, but since this is a new project should it not try to work with yarn pnp
from the get-go?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:14 (6 by maintainers)
Top Results From Across the Web
Troubleshooting - Vite
You will need to either: Switch to another package manager (e.g. pnpm , yarn ) Remove & from the path to your project....
Read more >engine.io-client | Yarn - Package Manager
This is the client for Engine.IO, the implementation of transport-based cross-browser/cross-device bi-directional communication layer for Socket.IO.
Read more >import fetch from "node-fetch"; ^^^^^^ syntaxerror: cannot use import ...
i am getting this error when i build and run server. Error disappears when not using firebase-admin. I tried adding firebase-admin , firebase-admin/app...
Read more >oeA - River Thames Conditions - Environment Agency - GOV.UK
Tf g1 soundwave, Face mask with banana, Ya waridal habib syech, 10198 vs 10019, ... Mathew buelt, Manas sahoo linkedin, Plugin admin exec...
Read more >Learn from 425 web development courses on egghead
authentication with GitHub; authorization with RLS; merging client and server state with realtime events; deploying a Remix app to Vercel. This course is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The code fails here https://github.com/inspect-js/object-inspect/blob/main/index.js#L68
Because
./util.inspect.js
is disabled for the browser here (which Vite fails to handle in PnP mode): https://github.com/inspect-js/object-inspect/blob/4ec8893ea9bfd28065ca3638cf6762424bf44352/package.json#L74-L76And inside it a node’s builtin
util
is being imported: https://github.com/inspect-js/object-inspect/blob/4ec8893ea9bfd28065ca3638cf6762424bf44352/util.inspect.js#L1Looks like PnP loose mode allows the bundler to pick up the util npm package that is present in your package tree but is not accessible in strict PnP mode because it’s not a dependency of
object-inspect
.So, cause is the same, but PnP loose mode is only an accidental workaround in this case, which actually might be unwanted behavior.
It seems I’m hitting this in the storybook builder for vite as well. I find that in my case, setting
pnpMode
toloose
also resolves the issue, in case that’s useful information at all. Here’s a reproduction: https://github.com/IanVS/vite-pnp-object-inspect.