-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
fix(resolve): prioritize main
field over mainFields
for require
s
#17330
base: main
Are you sure you want to change the base?
fix(resolve): prioritize main
field over mainFields
for require
s
#17330
Conversation
|
e603656
to
7484d8b
Compare
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ analogjs, astro, histoire, laravel, marko, nuxt, quasar, qwik, rakkas, remix, unocss, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-pages, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress |
I'm not sure if this is correct. |
@bluwy I've just updated the PR's description with the package(s) that I was having issues with 👍 Also to give you more context, the whole thing here is that I'm trying to run a Remix application inside workerd via the Vite Environment API without prebundling the react code. |
I'm curious how this happens in the first place. According to vite/packages/vite/src/node/ssr/fetchModule.ts Lines 39 to 48 in c373251
main field should be used when resolving bare imports. If it's not a bare import (e.g. it's in noExternal which Vite rewrites to a different path. Or a plugin resolves it to something else. Or perhaps you're testing the packages linked locally?), then Vite will process these packages, however Vite won't handle CJS and require() correctly.
In that case, I'd recommend passing the packages to
If the problem started from this, would it be possible for |
Description
When a
require
is performed the modules resolution currently prioritizes themainFields
option over the fact that arequire
has been used, this (especially given the defaultmainFields
value) can lead torequire
s being resolved to browser entries instead of a potential cjsmodule
entry. This PR addresses this by priotizing a potentialmain
field over themainField
.Details on how we encountered this issue
This was encountered as an issue when trying to run Remix code inside the
workerd
runtime via the environments API, there we encountered situations in which some modules imported viarequire
wouldrequire
packages but would receive esm entries instead of cjs ones, causing the following issue:This happened when
react-router-dom
(package.json) was beingrequire
d from@remix-run/react
(code)by adding some ad-hoc hacks to make the above work this issue would show up again
for
react-router
(packae.json)require
d fromreact-router-dom
itself (code)by also hacking the above we'd re-encounter the issue with:
@remix-run/router
(package.json) beingrequire
d fromreact-router
(code)and so on...