Replies: 4 comments 21 replies
-
I'm importing some packages such as vite.ssrLoadModule("...") [Module: null prototype] {
__esModule: true,
default: { default: [Function: Slider] }
} How to fix this without enabling this option? |
Beta Was this translation helpful? Give feedback.
-
In case this feedback is helpful; That I could experience, the ecosystem's state for node.js likely does not fit this removal well.
So a few key points come to mind: ESM without interop may be unrealistic For any server project of a decent size, the task of writing strict ESM (without interop) may be too error-prone and require too much maintenance to be viable because of historical node.js and typescript decisions. Providing interop support would match browser builds: That's solution 1 (Make prod match dev behaviour). Although I understand supporting externalized dependencies may carry different challenges, the final dev experience would be more consistent for Vite users across browser and ssr builds. CJS builds need legacy.proxySsrExternalModules Projects that still compile to CJS (as I suspect may be common for node.js projects) were not affected by this dev vs prod discrepancy and using By CJS builds, I mean this:
|
Beta Was this translation helpful? Give feedback.
-
I don't understand why Vite can't do this transformation |
Beta Was this translation helpful? Give feedback.
-
Hi everyone, Why I'm writing: I recently upgraded my project to Vite 5 and found that I needed to use the My scenario: Following the guide at https://vite.dev/guide/ssr#pre-rendering-ssg, I wrote a script to generate static pages for my site once during the build process. SyntaxError: [vite] Named export 'NMessageProvider' not found. The requested module 'naive-ui' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from 'naive-ui';
const { NConfigProvider, NMessageProvider } = pkg; What I expect: I expect to have one codebase for both client and server, but legacy CJS libraries stop working only on the server side. Thoughts: Perhaps I am taking the wrong approach. If so, what would be a recommended way to generate both client and server parts with minimal differences? |
Beta Was this translation helpful? Give feedback.
-
legacy.proxySsrExternalModules
If you have concerns, questions, or bug reports as to why you still need this option, please leave a comment here!
Notes
This comment brought up that this option is still useful when outputting as CJS. In a CJS build, Rollup is able to bundle named imports of externalized CJS packages to something that works in a CJS runtime.
Our dev runtime usually don't take in account of build-related settings, and unfortunately we had removed
ssr.format: 'cjs'
that would've allowed us to avoid checking build-related settings, but I think this may be an exception for now to get CJS somewhat working.Beta Was this translation helpful? Give feedback.
All reactions