-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Add node exports for CJS #1099
Add node exports for CJS #1099
Conversation
i don't think this is needed. If at all we would have to use the but you can use vite plugin svelte in cjs today if you really have to: https://github.com/sveltejs/vite-plugin-svelte/blob/main/docs/faq.md#how-can-i-use-vite-plugin-svelte-from-commonjs |
Oh, I didn't know about the module-sync condition. Thanks! The problem of the current solution proposed is that it requires me to do an async operation (awaiting the import), and on the constraints that I work with I need the import to be synchronous. I understand if from a principle base you wouldn't want to add this to the package.json to disallow CJS imports and if so, I can fork this plugin for my needs, but is there any practical downsides of adding this to the package.json? Let me know if you want me to edit this PR or we can just close it for now, and thanks for replying so quickly! :) |
can you share where you need it sync? vites defineConfig accepts an async function so you can require vite.config.js and it'll still work with dynamic imports inside |
I'll admit it's not a pretty usual case, but I'm not using vite.configs directly. This is for a framework that accepts vite based templates to render as microfrontends. For that it just does internally a "vite build". The template has a strict api that just needs to have an exported function "compile" with an api like this: module.exports.compile = createCompile({ this file will be automatically required by the framework when pointing the template you are using (will look for node_modules and do it itself). Because of these constraints I can't put anywhere on that file a promise, since it won't resolve. It's kind of niche, but I thought it wouldn't break anything to explicitly put the exports for cjs. For now I already put a workaround as a postinstall script to add it on the template scaffold. |
another option proposed by @bluwy is to change I still believe Vite is also going to remove its explicit cjs support at some point (originally slated for vite6, but postponed vitejs/vite#13928 ). |
Yeah, that's fine, the fact that my setup requires to be synchronous is because its an older framework and doing changes to that amounts to great deal of pain, so if CJS support gets explicitly removed we will just stick with Vite 6 + Svelte 5 which is fine. Thanks for the response, and I guess we can close this for now! |
Since the newest versions of node supports require(esm), adding this exports make that work, (without it, requiring fails with a ERR_PACKAGE_PATH_NOT_EXPORTED). I need for one of my projects that still can't be moved from CJS and AFAIK adding this extra definition should do no harm.