node.jstypescriptexpressvisual-studio-code

Why does vs code on the nodejs project not give import suggestions when using expressjs in code?


why does vs code on the nodejs project not give import suggestions when using expressjs in code? I created node typescript project, I installed express. when I write in the code

 export const server = express()

vs code highlights the error that it cannot find express, and does not give me suggestions from where to import it, as it works for example on react How can I enable import suggestions? enter image description here

Here is my tsconfig.json. I tried any different settings, but it did not help

{
  "compilerOptions": {
    "lib": ["es2023"],
    "module": "node16",
    "target": "es2022",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "moduleResolution": "node16",
    "outDir": "dist",
    "rootDir": "src",
    "baseUrl": ".",
    "sourceMap": true,
    "paths": {
      "@/*": ["src/*"]
    },  
    "checkJs": true
  },
  "include": ["src/**/*.ts"],
  "exclude": ["node_modules", ".idea", "**/*.test.ts"]
}

This is package.json dependencies:

    
  "devDependencies": {
    "@types/express": "^5.0.0",
    "@types/node": "^22.8.5",
    "ts-node-dev": "^2.0.0",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.6.3"
  }

Solution

  • This problem exist because in express lib in node_modules in index.d.ts file no export of 'express' function, instead it exports 'e' function. So we must use 'e' from 'express' instead of 'express'. enter image description here