Replies: 6 comments 5 replies
-
Hey, did you found a solution for that or does anyone have some debug ideas? We get the same error for SSR |
Beta Was this translation helpful? Give feedback.
-
I've now run into this same issue today. I've been debugging to find this out. I'll post here if I find out the issue |
Beta Was this translation helpful? Give feedback.
-
I just spent an absurd amount of time debugging the same issue and here is what I found. In our case, it was being caused by an import of a @Turf package. I figured it out by painstakingly disabling deps one by one and testing the build on production. The issue with @Turf is that it has 2 dist packages: one for ES and one for commonJS. For some reason when I hovered over the import statement to see the actual file it's targetting, it was pointing to the CJS version. The @Turf package.json seems to be configured correctly to target ES modules in a module project, so I sadly can't give any resolution to this issue. This led me to believe that it probably had something to do with commonJS imports, which led me to the checkout the rollup-common-js plugin docs and there I found this config option: requirereturnsdefault. Here you will see very similar code that is just like the one mentioned in the previous comment from @mnickolay I still don't fully understand what is going because, or if this is the actual right solution, but by the end of this ordeal I gave up all hope and was in complete monkeybrain mode just randomly trying anything hoping to solve this issue. In the end it was solved by setting the following option in vite.config.js
Whoever is reading this, I hope this helps you in some way and that you find this thread hopefully sooner than later. |
Beta Was this translation helpful? Give feedback.
-
Just spent two weeks debugging the same thing. In my case the issue was caused by the i18n plugin: i18next-browser-languagedetector.
|
Beta Was this translation helpful? Give feedback.
-
For me, I was working on an electron, vue3, express and vite application. What fixed it for me was installing all the packages that the express app will use as |
Beta Was this translation helpful? Give feedback.
-
I once more ran into this problem. The above solutions did not help. TL;DR: add the affecting commonjs package to vite's // vite.config.js
export default defineConfig({
build: {
commonjsOptions: {
include: ["node_modules/prop-types"],
}
}
// ...
}) I have a custom component library that leverages // rollup.config.js
export default [
{
external: ["reactstrap"],
// ...
}
] The consuming package of this custom library would list this package in its dependencies, but vite would not bundle the // vite.config.js
export default defineConfig({
build: {
minify: false,
commonjsOptions: {
requireReturnsDefault: "auto",
}
}
// ...
}) When I ran the output of the build in my browser via docker, I would get this console error:
This lead me to the // vite.config.js
export default defineConfig({
build: {
commonjsOptions: {
include: ["node_modules/prop-types"],
}
}
// ...
}) Vite version: 5.4.11 |
Beta Was this translation helpful? Give feedback.
-
I try to migrate the React app from craco to Vite but I build the app and serve from production folder I get this error. What's solution to fix
here's my error display
The problem I tried to fix is remove the commonjs() plugin to build it's working when serve with production but the some function not working on my application eg. react-hook-form, react-router. Now I have no idea to solve.
here's my error when removed the commonjs() plugin
vite.config.ts
tsconfig.json
dependencies in package.json
system
Beta Was this translation helpful? Give feedback.
All reactions