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.js
to 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"
}
}
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.js
to 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"
}
}
Share
Improve this question
edited yesterday
avifen
1,0037 silver badges18 bronze badges
asked Feb 16 at 16:42
Rakesh NagarkarRakesh Nagarkar
12 bronze badges
New contributor
Rakesh Nagarkar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
10
|
Show 5 more comments
1 Answer
Reset to default 1You have in your dependency both node-redis
and io-redis
.
So you should choose.
For node-redis, the one called redis
use:
import { createClient } from 'redis';
const client = createClient();
await client.connect();
For io-redis:
const Redis = require("ioredis");
const redis = new Redis();
But the best is always valkey-glide :P
import { GlideClient } from "@valkey/valkey-glide";
const addresses = [
{
host: "localhost",
port: 6379,
},
];
const client = await GlideClient.createClient({
addresses: addresses,
});
package.json
file. – jQueeny Commented Feb 16 at 18:03@fs
is 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)? – M. Damian Mulligan Commented Feb 16 at 19:09