Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic Example not going through #2680

Open
eliassal opened this issue Jan 1, 2024 · 2 comments
Open

Basic Example not going through #2680

eliassal opened this issue Jan 1, 2024 · 2 comments
Labels

Comments

@eliassal
Copy link

eliassal commented Jan 1, 2024

Description

Hi, I am new to node and trying to run the basic example you provide. When I run it I get

import { createClient } from 'redis';
^^^^^^

SyntaxError: Cannot use import statement outside a module
at internalCompileFunction (node:internal/vm:73:18)
at wrapSafe (node:internal/modules/cjs/loader:1187:20)
at Module._compile (node:internal/modules/cjs/loader:1231:27)
at Module._extensions..js (node:internal/modules/cjs/loader:1321:10)
at Module.load (node:internal/modules/cjs/loader:1125:32)
at Module._load (node:internal/modules/cjs/loader:965:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
at node:internal/main/run_main_module:23:47

Node.js v20.0.0

Node.js Version

v20.0.0

Redis Server Version

latest docker image

Node Redis Version

redis@4.6.12

Platform

Windows 10

Logs

import { createClient } from 'redis';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1187:20)
    at Module._compile (node:internal/modules/cjs/loader:1231:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1321:10)
    at Module.load (node:internal/modules/cjs/loader:1125:32)
    at Module._load (node:internal/modules/cjs/loader:965:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47

Node.js v20.0.0
@eliassal eliassal added the Bug label Jan 1, 2024
@SiNONiMiTY
Copy link

@eliassal not a bug of node-redis, maybe you have not configured the "module" type in your package.json, hence Node is treating it as CommonJS, which does not support import statements

try to add this on your package.json

{
    "type": "module" <-- THIS ONE ONLY
}

@ranjitmahadik
Copy link

@eliassal you can try below code to import createClient.

const { createClient } = require('redis');

const client = createClient().on('error', err => console.log("[Error]: ", err)).connect();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants