Replies: 6 comments 2 replies
-
I just ran into the same problem. |
Beta Was this translation helpful? Give feedback.
-
@Fumler |
Beta Was this translation helpful? Give feedback.
-
trying to solve the same problem |
Beta Was this translation helpful? Give feedback.
-
Trying to solve the same problem |
Beta Was this translation helpful? Give feedback.
-
Has any solution been found to maintain both CommonJS and the module configuration offered by Vite? |
Beta Was this translation helpful? Give feedback.
-
Considering a package I've built as a
optimizeDeps: {
include: ['circuit-sketcher-core'],
},
...
export default defineConfig({
...
build: {
commonjsOptions: {
include: [/circuit-sketcher-core/, /node_modules/],
},
},
...
}); See full This aligns exactly with the Monorepos and Linked Dependencies from Vite guide, so no need for additional plugins any more. I also want to point out that the version of Vite I am using is 6. |
Beta Was this translation helpful? Give feedback.
-
We have some files that we use in node + the browser that we would like to keep CommonJS for now as the node tooling we use does not support using ESM for now. And after reading the docs for
optimizeDeps
I've tried a few things but can't get it to work, so I'm wondering if there is something I am misunderstanding here?To me this indicates that I should be able to add imports that are CommonJS to
optimizeDeps.include
or am I misunderstanding the docs?Example from StackBlitz: https://stackblitz.com/edit/vitejs-vite-swxhbd?file=vite.config.ts
src/App.tsx
is where I am importing the CommonJS file. If you open the console you can see the error:So my assumption was that Vite would transform e.g.
module.exports
toexport default
in this case, but it does not, the transform seems to keep themodule.exports
part:Any guidance here would be greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions