node.jstypescriptexpresskubernetesskaffold

Could not find a declaration file for module 'cookie-session'


I have a Typescript project and I get the following error.

[auth] [ERROR] 09:55:34 ⨯ Unable to compile TypeScript:

[auth] src/app.ts(3,27): error TS7016: Could not find a declaration file for module 'cookie-session'. '/app/node_modules/cookie-session/index.js' implicitly has an 'any' type.

[auth] Try npm i --save-dev @types/cookie-session if it exists or add a new declaration (.d.ts) file containing declare module 'cookie-session';

my package.json

{
  "name": "auth",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "ts-node-dev src/index.ts",
    "test": "jest --watchAll --no-cache"
  },
  "jest": {
    "preset": "ts-jest",
    "testEnvironment": "node",
    "setupFilesAfterEnv": [
      "./src/test/setup.ts"
    ]
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@types/express": "^5.0.0",
    "cookie-session": "^2.1.0",
    "express": "^4.21.2",
    "express-async-errors": "^3.1.1",
    "express-validator": "^7.2.1",
    "jsonwebtoken": "^9.0.2",
    "mongoose": "^8.12.1",
    "ts-node-dev": "^2.0.0",
    "typescript": "^5.8.2"
  },
  "devDependencies": {
    "@types/cookie-session": "^2.0.49",
    "@types/jest": "^29.5.14",
    "@types/jsonwebtoken": "^9.0.9",
    "@types/supertest": "^6.0.2",
    "jest": "^29.7.0",
    "mongodb-memory-server": "^10.1.4",
    "supertest": "^7.0.0",
    "ts-jest": "^29.2.6"
  }
}

I run this in a Kubernetes cluster using skaffold.

When I try to do this:

// @ts-ignore
import cookieSession from 'cookie-session'

I get

[auth] Compilation error in /app/src/middleware/current-user.ts

[auth] [ERROR] 10:06:31 ⨯ Unable to compile TypeScript:

[auth] src/middleware/current-user.ts(2,17): error TS7016: Could not find a declaration file for module 'jsonwebtoken'. '/app/node_modules/jsonwebtoken/index.js' implicitly has an 'any' type.

[auth] Try npm i --save-dev @types/jsonwebtoken if it exists or add a new declaration (.d.ts) file containing declare module 'jsonwebtoken';

[auth] src/middleware/current-user.ts(18,12): error TS2339: Property 'session' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.

[auth] src/middleware/current-user.ts(23,36): error TS2339: Property 'session' does not exist on type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.


Solution

  • I figured out what was wrong with my project, I had this line in my Dockerfile.

    RUN npm install --omit=dev