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

Error: Module '"express"' has no exported member #6089

Open
kaiunido opened this issue Oct 27, 2024 · 3 comments
Open

Error: Module '"express"' has no exported member #6089

kaiunido opened this issue Oct 27, 2024 · 3 comments

Comments

@kaiunido
Copy link

Hi...

I'm using express 5.0.1 (tried with last 4.x too) and trying to use with module.

And change my package.json adding:

"exports": "./dist/index.js",
  "type": "module",
  "engines": {
    "node": ">=20"
  },

package.json dependencies and scripts:

"scripts": {
    "start": "tsc-watch --onSuccess \"node dist/index.js\""
  },
...
"dependencies": {
    ...
    "express": "^5.0.1",
    ...
  },
"devDependencies": {
    "@eslint/js": "^9.13.0",
    "@tsconfig/node20": "^20.1.4",
    "@types/express": "^5.0.0",
    "@types/node": "^22.8.1",
    "eslint": "^9.13.0",
    "eslint-config-prettier": "^9.1.0",
    "eslint-plugin-prettier": "^5.2.1",
    "globals": "^15.11.0",
    "tsc-watch": "^6.2.0",
    "typescript": "^5.6.3",
    "typescript-eslint": "^8.11.0"
  },

And my tsconfig:

{
  "extends": "@tsconfig/node20/tsconfig.json",
  "compilerOptions": {
    "rootDir": "src",
    "outDir": "dist",
    "sourceMap": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "noEmitOnError": true,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "resolveJsonModule": true
  },
  "compileOnSave": true,
  "include": ["src/**/*", "src/locales/**/*.json"],
  "exclude": ["**/*.spec.ts"]
}

I tried change types version, express version, make a lot of search but don't find any way to fix.
When I run with pnpm start i`m getting a lot of errors like:

(4,15): error TS2305: Module '"express"' has no exported member 'NextFunction'.
(4,29): error TS2305: Module '"express"' has no exported member 'Request'.
(4,38): error TS2305: Module '"express"' has no exported member 'Response'.
(1,15): error TS2305: Module '"express"' has no exported member 'Response'.
(3,15): error TS2305: Module '"express"' has no exported member 'Response'.
# this one is in the "import express from 'express'"
src/index.ts(1,8): error TS1192: Module '"U:/projects/express/src/index"' has no default export.

Is the same with import ... or import type ...
image

If anyone can give me some light or direction I would appreciate it.

Thank you... :D

@kaiunido
Copy link
Author

kaiunido commented Oct 28, 2024

If it helps, here is a repo with the minimum to reproduce the behavior: https://github.com/kaiunido/express-module-error

Edit: for a little more context, I was trying to test @auth/express and it is ESM only.

@Abdel-Monaam-Aouini
Copy link

you can enable esModuleInterop to allow importing default exports without explicit naming.
Add the following option to your tsconfig.json:

{
  "compilerOptions": {
    "esModuleInterop": true
  }
}

@kaiunido
Copy link
Author

kaiunido commented Oct 28, 2024

@Abdel-Monaam-Aouini this option is already enabled in the extended tsconfig:

"extends": "@tsconfig/node20/tsconfig.json",


{
  "$schema": "https://json.schemastore.org/tsconfig",
  "_version": "20.1.0",

  "compilerOptions": {
    "lib": ["es2023"],
    "module": "node16",
    "target": "es2022",

    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "moduleResolution": "node16"
  }
}

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

No branches or pull requests

3 participants