I’m currently using Vite to build my React app. I use react-comment-section
After I used vite build
and deploy it to Firebase hosting. I always get this error: required is not defined
And I’ve found that this error comes from this react-comments-section
package
This is my vite.config.js
I’ve tried transformMixedEsModules
and commonJs
but both of them don’t work:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import commonjs from "vite-plugin-commonjs";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), commonjs({
filter(id) {
if (id.includes('node_modules/@pmhieu/react-comments-section')) {
return true;
}
},
})],
define: {
global: {},
},
build: {
commonjsOptions: { transformMixedEsModules: true }
},
optimizeDeps: {
include: ["@pmhieu/react-comments-section"],
},
resolve: {
alias: {
src: "/src",
},
},
});
What is the correct way to build my app and this package?
2