I am using ioredis in my Node.js + Express project with ES modules ("type": "module" in package.json). When I try to import Redis like this:
import {Redis} from "ioredis";
import dotenv from "dotenv";
dotenv.config();
const redis = new Redis(process.env.UPSTASH_REDIS_URI);
// ✅ Correct Export (Named + Default)
export { redis };
export default redis;
I get the error:
Uncaught SyntaxError: The requested module
'/@fs/D:/Main/Web_Development/Projects/E-Commerce-
Store/node_modules/ioredis/built/index.js?v=0293eaae'
does not provide an export named 'Redis' (at redis.js:1:9)
I tried changing the import statement to:
import Redis from "ioredis";
But this resulted in another error:
Uncaught SyntaxError: The requested module
'/@fs/D:/Main/Web_Development/Projects/E-Commerce-
Store/node_modules/ioredis/built/index.js?v=0293eaae'
does not provide an export named 'default' (at redis.js:1:8)
- I also checked
node_modules/ioredis/built/index.jsto see if Redis is exported, but couldn't find a named export. - I expected the module to import Redis correctly without errors.
- i am using the latest
ioredis, version which is 5.5.0
here's my vite.config.js:
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
export default defineConfig({
plugins: [react()],
server: {
proxy: {
"/api": {
target: "http://localhost:5000",
},
},
},
build: {
rollupOptions: {
// Exclude ioredis from the final build
external: ["ioredis"],
},
},
optimizeDeps: {
// Prevent Vite from pre-bundling ioredis
exclude: ["ioredis"],
},
});
here's my package.json file:
{
"name": "e-commerce-store",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"dev": "nodemon backend/server.js",
"start": "node backend/server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"type": "module",
"license": "ISC",
"description": "",
"dependencies": {
"bcryptjs": "^2.4.3",
"cloudinary": "^2.5.1",
"cookie-parser": "^1.4.7",
"cors": "^2.8.5",
"dotenv": "^16.4.7",
"express": "^4.21.2",
"ioredis": "^5.5.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.9.5",
"razorpay": "^2.9.5",
"redis": "^4.7.0",
"safe-buffer": "^5.2.1",
"stripe": "^17.5.0"
},
"devDependencies": {
"nodemon": "^3.1.9"
}
}
package.jsonfile.@fsis typically something I see in Vite logs). If you are could you please post your Vite config as well as any other configurations (e.g. TypeScript)?