Skip to content

SyntaxError: Named export 'commandOptions' not found. #3022

@mihalacherazvan

Description

@mihalacherazvan

Description

Hello!

I wrote a custom cache handler for a Next.js app. The only import i use is createClient:

import {createClient} from 'redis';

const client = createClient({
    url: process.env.REDIS_URL || 'redis://localhost:6379',
});

const result = await client
    .withCommandOptions({signal: AbortSignal.timeout(10000)})
    .get('key');

Even if i remove the .withCommandOptions(...) call, during the build i get the following error:

SyntaxError: Named export 'commandOptions' not found. The requested module 'redis' is a CommonJS module, which may not support all module.exports as named exports.

Node.js Version

20.15.1

Redis Server Version

7.2.4

Node Redis Version

5.6.0

Platform

Linux (WSL)

Logs

2025-07-18 17:28:56 > next build --experimental-build-mode generate && next start
2025-07-18 17:28:56 
2025-07-18 17:28:57 Attention: Next.js now collects completely anonymous telemetry regarding usage.
2025-07-18 17:28:57 This information is used to shape Next.js' roadmap and prioritize features.
2025-07-18 17:28:57 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
2025-07-18 17:28:57 https://nextjs.org/telemetry
2025-07-18 17:28:57 
2025-07-18 17:28:57    ▲ Next.js 15.1.6
2025-07-18 17:28:57    - Experiments (use with caution):
2025-07-18 17:28:57      · staleTimes
2025-07-18 17:28:57 
2025-07-18 17:28:57    Creating an optimized production build ...
2025-07-18 17:28:57    Collecting page data ...
2025-07-18 17:29:04 
2025-07-18 17:29:04 > Build error occurred
2025-07-18 17:29:04 [SyntaxError: Named export 'commandOptions' not found. The requested module 'redis' is a CommonJS module, which may not support all module.exports as named exports.
2025-07-18 17:29:04 CommonJS modules can always be imported via the default export, for example using:
2025-07-18 17:29:04 
2025-07-18 17:29:04 import pkg from 'redis';
2025-07-18 17:29:04 const { commandOptions } = pkg;
2025-07-18 17:29:04 ] {
2025-07-18 17:29:04   type: 'SyntaxError'
2025-07-18 17:29:04 }

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions