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 ignoring resolve.mainFields in configuration #217

Open
vembye opened this issue Feb 15, 2024 · 3 comments
Open

Vite ignoring resolve.mainFields in configuration #217

vembye opened this issue Feb 15, 2024 · 3 comments

Comments

@vembye
Copy link

vembye commented Feb 15, 2024

Problem

Using the default config, vite doesn't seem to respect the resolve.mainField.

We are using ws in our electron setup, and when using vite-plugin-electron vite kept importing the browser module from ws, corrupting the build.

Seeing the correct approach in default config, ignoring the browser as a mainField. Unfortunately vite kept using the browser field.

Turns out resolve.mainField is not respected when targeting browser (which is vite default).

Solution

Enforce main entry build to be ssr: true.

I'm ready to create PR if issue is accepted.

@caoxiemeihao
Copy link
Member

Hey! 👋
However, you can override the default configuration by configuring electron({}) in vite.cinfig.ts.

@vembye
Copy link
Author

vembye commented Mar 13, 2024

Definitely, and how we have done it, so change not required to get it working.

But debugging of multiple hours to figure out why the (already existing) clause of handling browser field didn't take effect, could have been avoided, and should for new-comers IMO 💡

It would have saved me a lot of frustrations at least 🙏🏻

@caoxiemeihao
Copy link
Member

Are you talking about import the ws module in the Renderer process? If the Main process import the ws module, it will not look for the browser module.
The default config only acting on Main process and Preload scripts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants