-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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 fails to load browser field from engine.io-client when using yarn berry pnp #1979
Comments
There are multiple issues for yarn2/pnp that do not affect the other package managers. It isn't that vite isn't trying to support it, it just looks like yarn2/pnp requires special attention that using other package managers don't. Just picking a few comments out of the issues with problems around yarn2/pnp. |
I suppose yarn 2 is the issue in this case. It's not particularly a major problem for me (I'll just unplug whatever's broken or run in node-modules mode). Just wanted to get this out there. |
Another repro here: https://github.com/swandir/vite-pnp-browser-field It demonstrates that the problem only occurs when the dependency remaps nested modules via "browser" field. The problem also affect dependency optimizing specifically. Production bundling works as expected.
I also tried to reproduce this within the optimize-deps playground, but my test passes |
Is there currently any known workaround this issue? |
Adding the package to optimizeDeps.exclude may fix this particular problem, but it seems like there's another issue with socket.io-client
|
Thank you. For me the problem is with Adding |
I haven't tried, but disabling optimization for all related deps or at all might help. Otherwise, opting out of PnP (via nodeLinker: node-modules) seems to be the only option. |
I actually fixed it using an alias for now. For React mapbox Gl I used this:
This is basically what the Note that if you use SSR then it wouldn't work or you would need to have that alias set dynamically only for the browser. It's a very hacky solution but well at least it works in the meantime! |
Hey @mijamo, can you please help me fix the same issue? This is the error I get when I don't exclude
Could this be in any way related to the fact that I use TypeScript in my project? I've upgraded Other dependencies that I have:
The same error occurred before I upgraded This is my first time trying out vite so I have no idea what I can do to fix this? |
I am using You error is most likely related to typescript and |
Thanks @mijamo! I've found the same SO thread, but to no avail. I'll create an issue on react-mapbox-gl repo. |
I've done some debugging on this and stumbled over this place vite/packages/vite/src/node/optimizer/esbuildDepPlugin.ts Lines 57 to 60 in c287c20
Later during resolution
which is used to access closest package manifest to a module in order to resolve browser field mappings. vite/packages/vite/src/node/plugins/resolve.ts Lines 753 to 760 in c287c20
But the Does anyone know what was the idea behind this Removing this special case for PnP and replacing it with just @yarnpkg/esbuild-plugin-pnp seems to fix the problem of locating
Any pointers? |
It seems I'm hitting this in the storybook builder for vite as well. I find that in my case, setting |
The code fails here Because And inside it a node's builtin Looks 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 So, cause is the same, but PnP loose mode is only an accidental workaround in this case, which actually might be unwanted behavior. |
Describe the bug
When using
yarn berry
inpnp
mode, Vite fails to properly load the package.jsonbrowser
field fromengine.io-client
. This results in browser polyfills not loading.Reproduction
yarn create @vitejs/app
vue-ts
cd
into projectyarn add engine.io-client
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
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 withyarn pnp
from the get-go?The text was updated successfully, but these errors were encountered: