Recently I tried to build my project to deploy it but I got this error every time try to run npm run build
.......
node_modules/react-redux/dist/react-redux.mjs (7:45): "default" is not exported by "node_modules/react/index.js", imported by "node_modules/react-redux/dist/react-redux.mjs".
✓ 607 modules transformed.
x Build failed in 6.71s
error during build:
RollupError: node_modules/react-redux/dist/react-redux.mjs (2:9): "useSyncExternalStoreWithSelector" is not exported by "node_modules/use-sync-external-store/with-selector.js", imported by "node_modules/react-redux/dist/react-redux.mjs".
file: D:/Activity/NPT/personal-frontend/node_modules/react-redux/dist/react-redux.mjs:2:9
1: // src/index.ts
2: import * as React2 from "react";
^
3: import { useSyncExternalStoreWithSelector as useSyncExternalStoreWithSelector2 } from "use-sync-external-store/with-s...
at getRollupError (file:///D:/Activity/NPT/personal-frontend/node_modules/rollup/dist/es/shared/parseAst.js:392:41)
at error (file:///D:/Activity/NPT/personal-frontend/node_modules/rollup/dist/es/shared/parseAst.js:388:42)
at Module.error (file:///D:/Activity/NPT/personal-frontend/node_modules/rollup/dist/es/shared/node-entry.js:13688:16)
at Module.traceVariable (file:///D:/Activity/NPT/personal-frontend/node_modules/rollup/dist/es/shared/node-entry.js:14136:29)
at ModuleScope.findVariable (file:///D:/Activity/NPT/personal-frontend/node_modules/rollup/dist/es/shared/node-entry.js:11817:39)
at Identifier.bind (file:///D:/Activity/NPT/personal-frontend/node_modules/rollup/dist/es/shared/node-entry.js:7311:40)
at CallExpression.bind (file:///D:/Activity/NPT/personal-frontend/node_modules/rollup/dist/es/shared/node-entry.js:4749:28)
at CallExpression.bind (file:///D:/Activity/NPT/personal-frontend/node_modules/rollup/dist/es/shared/node-entry.js:8975:15)
at ExpressionStatement.bind (file:///D:/Activity/NPT/personal-frontend/node_modules/rollup/dist/es/shared/node-entry.js:4753:23)
at Program.bind (file:///D:/Activity/NPT/personal-frontend/node_modules/rollup/dist/es/shared/node-entry.js:4749:28)
My package.json is this
{
"name": "cvtemplate",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --port 3000 --host",
"build": "vite build",
"lint": "eslint . --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"@ckeditor/ckeditor5-react": "^6.2.0",
"@reduxjs/toolkit": "^2.2.5",
"@tanstack/react-query": "^5.40.0",
"axios": "^1.6.8",
"ckeditor5-custom-build": "file:ckeditor",
"clsx": "^2.1.1",
"framer-motion": "^11.1.7",
"js-cookie": "^3.0.5",
"primereact": "^10.6.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.51.4",
"react-icons": "^5.1.0",
"react-multi-date-picker": "^4.4.1",
"react-player": "^2.16.0",
"react-redux": "^9.1.2",
"react-router-dom": "^6.23.0",
"react-slick": "^0.30.2",
"redux": "^5.0.1",
"redux-persist": "^6.0.0",
"redux-thunk": "^3.1.0",
"sweetalert2": "^11.11.0",
"vite-plugin-commonjs": "^0.10.1",
"yup": "^1.4.0"
},
"devDependencies": {
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.19",
"daisyui": "^4.10.2",
"eslint": "^8.57.0",
"eslint-plugin-react": "^7.34.1",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.6",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3",
"typescript": "^5.4.5",
"vite": "^5.2.0"
}
}
And vite.config.js
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 (["libs/ckeditor5/build/ckeditor.js"].includes(id)) {
return true;
}
},
}),
],
optimizeDeps: {
include: ["ckeditor5-custome-build"],
},
build: {
commonjsOptions: {
exclude: ["ckeditor5-custome-build"],
include: [],
},
},
});
I look for solution on many places but it seems its not happend too much. and I didn’t found anything usefull to solve the problem. mayabe i have to do somthing with vite rollback plugins but I’m not sure about it or I don’t know how to do it in right way.
Other thing that I faced with was related to some of my components that I import react-icons like this
import * as fa from "react-icons/fa";
so, it seems vite has some problem with namespace imports.