Error: Attempting to access the 'createClient' property of an undefined object - TypeError

Recently, I've been working on a project where I needed to create and store a session in redis. To achieve this, I referred to the API documentation provided by this GitHub repository https://github.com/tj/connect-redis.

However, I encountered an issue related to the word client while implementing the code. The error message stated: "The expected type comes from property 'client' which is declared here on type 'RedisStoreOptions'."

Here is the snippet of the code that led to the error:

import redis from 'redis';
import session from 'express-session';
import connectRedis from 'connect-redis';

const app = express();

    const RedisStore = connectRedis(session);
    const redisClient = redis.createClient({ legacyMode: true });
    redisClient.connect().catch(console.error);
    app.use(
        session({
          store: new RedisStore({ client: redisClient }),
          saveUninitialized: false,
          secret: "keyboard cat",
          resave: false,
        })
    )

The error seems to be directly related to the following line of code:

store: new RedisStore({ client: redisClient })

Specifically, it points out an issue with the word client within the code block.

Answer №1

rather than

import redis from 'redis';

opt for

import * as redis from 'redis';

Answer №2

Seems like you're working with TypeScript. I encountered a similar issue before. Have you tried installing these typings:

@types/redis
@types/connect-redis
@types/express-session

I faced an error with the client even after installing all 3 @types. Upon further investigation, I realized that redis does not require module declarations. Therefore, I only installed type definitions for express-session and connect-redis.

npm install @types/connect-redis @types/express-session --save-dev


yarn add @types/connect-redis @types/express-session -D

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using dynamic JavaScript appending with the location.href attribute and the ajax-cross-domain.com script for seamless integration

Once I assign this code to load the function on window.onload event: window.onload = initfunction; I am looking to add an AJAX cross domain script to the header: function initfunction() { var dh = document.getElementsByTagName('head')[0]; va ...

Ionic 2 - Dynamically Loading Segments

I am dealing with categories and dishes. Each dish is associated with a specific category. My goal is to send an http request to retrieve all the dishes belonging to a particular category. This will result in an array like: { Soup[{'Name',&ap ...

Utilize module.exports to export objects containing callback functions

I am currently diving into the world of writing my own modules for nodejs. My goal is to create various objects that I can use throughout my application. Here is the result I am aiming for: //assuming we have a database: Person_table(ID int A_I, NAME var ...

An error is anticipated when () is added, but surprisingly, I still encounter an error as well. This issue arises in React-Native and Typescript

I am still relatively new to React-Native, but I have been using React-Native, TypeScript, and integrating it with Firebase. An unusual error has occurred, which is visible in the screenshot below. However, when checking in VSC, the error seems to be non-e ...

Retrieving data from a div container on an active website

Imagine having a website similar to , where you want to automatically retrieve the time value every second and save it in a .txt file. Initially, I considered using OCR (optical character recognition) software for this task, but soon realized that relying ...

Guide on utilizing the <source> tag within v-img component in Vuetify.js?

When it comes to using webp images instead of jpg or png, some browsers may not support the webp format. In such cases, we can use the html tag < source > as demonstrated below, ensuring that at least a jpg image is displayed: <picture> < ...

working with a list of Python objects in a JavaScript environment

Currently, I am building a web application using Flask and Python. In my Python code, I have a class that can be parsed as JSON. class uItem: itemCount = 0 def __init__(self, id, name): self.id = id self.name = name I am trying to acce ...

Launching a modal within a Scala HTML list

When attempting to open a modal window within a list of items (specifically attachments), I am encountering difficulties retrieving the record ID from the list. The new modal window is opened with Scala, but I consistently receive an error stating that t ...

How to Incorporate Routes as Subroutes in Express.js

I am currently working on constructing a modular express.js server with a well-organized structure. I have experimented with using routes similar to components in React. index.js var syncsingle = require('./XYZ/syncsingle'); app.get('/sync ...

Transforming various date formats into the en-US format of mm/dd/yyyy hh:mm:ss can be accomplished through JavaScript

When encountering a date format in en-GB or European style (mm.dd.yyyy), it should be converted to the en-US format (mm/dd/yyyy). If the date is not already in en-US format, then it needs to be converted accordingly. ...

Is the RouterModule exclusively necessary for route declarations?

The Angular Material Documentation center's component-category-list imports the RouterModule, yet it does not define any routes or reexport the RouterModule. Is there a necessity for importing the RouterModule in this scenario? ...

Unlocking the res property in index.js from an HTML script tag: A step-by-step guide

Can anyone help me with the access variable issue I am facing? I have two files, index.js and page.ejs. These files require me to create a timer linked with datetimes stored on my local server. //index.js.. router.get('/mieiNoleggi', functio ...

Utilizing Node.js to Retrieve Data from MySQL

Hi there, I'm new to NodeJS and I'm curious about how to fetch a MySQL query like we do in PHP. $query = mysql_query("SELECT * FROM accounts"); while($fetch = mysql_fetch_array($query)) { echo $fetch['Username']; } How would this be ...

What are some effective ways to test asynchronous functions in React?

Looking for help to test async/Promise based methods in React components. Here is a simple example of a React component with async methods: import server from './server'; class Button extends Component { async handleClick() { if (await ca ...

Navigate to the AngularJS documentation and locate the section on monitoring data changes after a dropdown selection

Just starting out with AngularJS and Stack Overflow, so I hope I am asking this question correctly. I am working on a single-page application with editable text inputs. Two select drop-downs are used to control which data is displayed - one for time perio ...

The function '$.fn.<new_function>' is not a valid function in jQuery

UPDATE: code link with enhanced formatting: UPDATE: code upgraded with enhancements from JSHint http://pastebin.com/hkDQfZy1 I am attempting to utilize $.fn to establish a new function on jQuery objects by this method: $.fn.animateAuto = function(x,y) { ...

Experiencing a problem when switching between various divs on the website

Having difficulties with tracking the state of my application. Whenever I select a ticket on the edit form, the updated information is passed to all other tickets. I suspect there is an issue with how the state is being managed. The problematic function s ...

Hidden visibility of input field prevents the value from being posted

I have a dropdown menu containing numbers as options. When a user selects a number, I want to display an input box using jQuery based on their selection. However, the issue arises when I try to submit the values of these input boxes as they are not being s ...

"Troubleshooting: Why is the onError event not triggering

Has anyone else experienced issues with using a third-party API to fetch YouTube thumbnails with higher resolution, sometimes resulting in a code 404 error? I've been trying to replace the image source with a default YouTube thumbnail retrieved from i ...

What is the best way to eliminate the appended content within the tbody?

The code snippet below is functioning correctly. I am trying to retrieve the ID or Class of the appended data from the checkbox. However, when I use the following code $('.chk').click(function(){ console.log(cc);}), it does not work as expected. ...