0

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"
  }
}



10
  • I tried, it didn't gave me any errors, may be because of ioredis version ? Commented Feb 16 at 16:56
  • 2
    "i am using latest 'ioredis' version which is 10.8.2" but the latest version is only 5.5.0 on npm. Post your package.json file. Commented Feb 16 at 18:03
  • Are you using typescript by any chance? Commented Feb 16 at 19:08
  • 1
    Based on the console logs you posted you might be using Vite (@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)? Commented Feb 16 at 19:09
  • if this is the case you should use npm install --save-dev @types/node and import Redis and not { Redis } Commented Feb 16 at 19:13

1 Answer 1

1

You 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,
});
Sign up to request clarification or add additional context in comments.

5 Comments

"I'm trying to use @valkey/valkey-glide in my Node.js project on Windows, but I'm getting the following error: Error: Unsupported OS: win32, architecture: x64 Any suggestions would be appreciated!"
@RakeshNagarkar Hi, we still don't support windows, unfortunately. It is under development, but it will take some time. My general recommendation is to use WSL (in general TBH, since production servers are running on linux in usual).
See code.visualstudio.com/docs/remote/wsl my recommendation is to choose Ubuntu latest, as it the most popular server, and most chances that your apps in production will be run on.
after running my backend on "wsl" i am facing similar issue to previous one which is : Uncaught SyntaxError: The requested module '/@fs/D:/Main/Web_Development/Projects/E-Commerce-Store/node_modules/@valkey/valkey-glide/build-ts/index.js?v=5e84669d' does not provide an export named 'GlideClient
Did you try to install it on the WSL, or copy from the windows env? Do you want to join Valkey slack workspace and chat there? I'll be able to give better help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.