[Fixed] "No exported member" error when trying to add & { session: Express.Session } to type MyContext when following React, Express and Typescript tutorial


I’m delving into a React, Express and Typescript tutorial, to which I’m still pretty new to. Trying to better understand how setting up custom types works, and this is what I currently have.

In types.ts file:

import { Request, Response } from "express";
import { Redis } from "ioredis";
//import express from "express"; // adding this did not help
//import session from "express-session"; // adding this did not help

export type MyContext = {
    req: Request; // & { session: Express.Session }; // this is my troublesome line
    redis: Redis;
    res: Response;

When trying to add

& { session: Express.Session }

I get the error:

any Namespace ‘global.Express’ has no exported member

Versions of devDepencies and also depencies have been compared so that they’re the same. Trying the latest versions had no change.

    "@types/express": "^4.17.7",
    "@types/express-session": "^1.17.0",

    "express": "^4.17.1",
    "express-session": "^1.17.1",

Things I’ve tried:

  1. As comments show in the code, different import statements like express and/or session.

  2. Changing strictNullChecks from true to false in package.json.

  3. The latest versions of express, express-session, @types/express and @types/express-session.

  4. Change type to interface.

  5. Double checked similar questions before posting this (I had already looked here on SO and Google).

  6. Comparing the tutorial’s final code on GitHub vs my own code (they’re the same as far as I can tell).


The error you are getting tells you that it’s looking for a type in global.Express.Session. This is because you have no import called Express so it’s trying to find it on the global scope. Of course, this does not exist!

This worked for me, assuming that the Session type was supposed to come from the express-session library:

import { Request, Response } from "express";
import { Redis } from "ioredis";
import session from "express-session";

export type MyContext = {
    req: Request & { session: session.Session };
    redis: Redis;
    res: Response;

Leave a Reply

(*) Required, Your email will not be published