-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
module
field takes precedence over exports
in package.json
#11114
Comments
Oh this seems like the same issue I was fixing in #11234, but was reverted as it caused some issue with Vue + vite-node + Histoire (discussion). It seems like Vue expects the |
Interesting discussion. Maybe Vue needs fixes applied to its package.json file, there is a long-standing PR: And maybe Vite node also needs some fixes if it's not resolving like node does 😅 Maybe a transitional solution could be a vite plugin that checks node_modules and add For Nuxt and Firebase, this means extending the vite config only on server; defineNuxtConfig({
// ...
hooks: {
// cannot be added in nuxt's resolve.alias
'vite:extendConfig': (config, { isServer }) => {
if (isServer) {
config.resolve ??= {}
config.resolve.alias ??= {}
// @ts-ignore
config.resolve.alias['firebase/firestore'] = resolve(
nodeModules,
'firebase/firestore/dist/index.mjs'
)
// @ts-ignore
config.resolve.alias['@firebase/firestore'] = resolve(
nodeModules,
'@firebase/firestore/dist/index.node.mjs'
)
}
},
},
})
|
I think Vue's export is mostly fine (though there could be improvements), but mostly because the Vite + Vue ecosystem had always relied on the incorrect I think a transitional solution make sense but perhaps implemented in plugin-vue 🤔 We could try with the fix again and make sure Histoire passes. It shouldn't be a breaking change since it is incorrect behaviour currently. |
I think this needs to have higher priority because it makes it impossible (or hardly debuggable) to build applications that use packages like the firebase ones (which are correctly defined based on node). As an example, a project built with Nuxt will fail in very unexpected ways, sometimes with errors, sometimes without. Adding the workaround I posted doesn't work in all scenarios. In other words, currently cannot be used to build an ssr app with Firebase 😓 |
Describe the bug
Vite seems to prioritize the
module
field instead of theexports
like node does when importing from a library.I found this problem while using Firebase with Nuxt: it failed during dev but worked after building the project for production and serving the app with node. These are the other issues I found
Reproduction
https://stackblitz.com/edit/vitejs-vite-csrnaz
Steps to reproduce
npm i
+npm run dev
-> outputs modulenode main.js
-> outputs exportsIt should always output exports
System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: