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

Cannot find module '@fastify/session' or its corresponding type declarations #1217

Open
2 tasks done
RedBoardDev opened this issue Oct 5, 2024 · 5 comments
Open
2 tasks done

Comments

@RedBoardDev
Copy link

RedBoardDev commented Oct 5, 2024

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.0.0

Plugin version

3.0.1

Node.js version

20.17.0

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

UX425QA.306

Description

I have a typescript compilation error in the typing module.
When I run ‘tsc --noEmit’, I get this error:


node_modules/@fastify/passport/dist/session-managers/SecureSessionManager.d.ts:4:38 - error TS2307: Cannot find module '@fastify/session' or its corresponding type declarations.

4 import { FastifySessionObject } from '@fastify/session';
                                       ~~~~~~~~~~~~~~~~~~


Found 1 error in node_modules/@fastify/passport/dist/session-managers/SecureSessionManager.d.ts:4

And all my dependencies from package.json:

    "@fastify/cors": "^10.0.1",
    "@fastify/helmet": "^12.0.1",
    "@fastify/passport": "^3.0.1",
    "@fastify/rate-limit": "^10.1.1",
    "@fastify/secure-session": "^8.1.0",
    "@fastify/swagger": "^9.1.0",
    "@fastify/swagger-ui": "^5.0.1",
    "@prisma/client": "^5.20.0",
    "ajv": "^8.17.1",
    "ajv-formats": "^3.0.1",
    "bcrypt": "^5.1.1",
    "dotenv": "^16.4.5",
    "fastify": "^5.0.0",
    "handlebars": "^4.7.8",
    "json-schema-to-ts": "^3.1.1",
    "jsonwebtoken": "^9.0.2",
    "nodemailer": "^6.9.15",
    "passport-local": "^1.0.0"
  },
  "devDependencies": {
    "@types/bcrypt": "^5.0.2",
    "@types/cors": "^2.8.17",
    "@types/jsonwebtoken": "^9.0.7",
    "@types/node": "^22.5.5",
    "@types/nodemailer": "^6.4.16",
    "@types/passport": "^1.0.16",
    "@types/passport-local": "^1.0.38",
    "eslint-plugin-import": "^2.31.0",
    "eslint-plugin-unused-imports": "^4.1.4",
    "husky": "^9.1.6",
    "prettier": "^3.3.3",
    "prisma": "^5.20.0",
    "ts-node": "^10.9.2",
    "ts-node-dev": "^2.0.0",
    "tsconfig-paths": "^4.2.0",
    "typescript": "^5.6.0",
    "typescript-eslint": "^8.8.0"
  }

tsconfig.json:

{
"extends": "./tsconfig.base.json",
"ts-node": {
  "transpileOnly": true,
  "require": ["tsconfig-paths/register"]
},
"include": ["app/**/*.ts"],
"exclude": ["dist", "node_modules"]
}

tsconfig.base.json:

{
  "compilerOptions": {
    "lib": ["ESNext"],
    "moduleResolution": "node",
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "removeComments": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "sourceMap": true,
    "target": "ES2020",
    "esModuleInterop": true,
    "outDir": "./dist",
    "allowSyntheticDefaultImports": true,
    "resolveJsonModule": true,
    "types": ["node"],
    "typeRoots": ["./node_modules/@types", "./app/src/entities"],
    "baseUrl": "./app/src",
    "paths": {
      "@fonts": ["assets/fonts/*"],
      "@icons": ["assets/icons/*"],
      "@images": ["assets/images/*"],
      "@config/*": ["config/*"],
      "@entities/*": ["entities/*"],
      "@enums/*": ["enums/*"],
      "@libs/*": ["libs/*"],
      "@middlewares/*": ["middlewares/*"],
      "@repositories/*": ["repositories/*"],
      "@routes/*": ["routes/*"],
      "@services/*": ["services/*"],
      "@templates": ["templates/*"],
      "@utils": ["libs/utils/index.ts"]
    },
    "strictNullChecks": true
  }
}

Don't hesitate if you see any inconsistencies in these files too !

Link to code that reproduces the bug

No response

Expected Behavior

No response

@mcollina
Copy link
Member

I think this was introduced in #1198.
A workaround for you could be to use the skipLibCheck option.

cc @robwalkerco @simoneb - I have absolutely no idea how to type this.

@RedBoardDev
Copy link
Author

Yeah, but I want to avoid skipLibCheck to have a nice CI !
But for now I'm using it yes

@robwalkerco
Copy link
Contributor

robwalkerco commented Oct 15, 2024

The Session and Secure-session packages are used for some of the types, but they are dev dependencies

"@fastify/secure-session": "^8.0.0",
"@fastify/session": "^11.0.0",

This lets the types work great when developing, but causes the error when checking the types when the dev dependencies are not installed, such as in a production CI environment.

I'll have to do some research tomorrow on the best way to handle this scenario, as I guess the preference would be to avoid making them dependencies.

@robwalkerco
Copy link
Contributor

I've tried to find a nice way to make this work well, and have yet to find a great solution.

I have managed to make it work with some type changes in @fastify/session and @fastify/secure-session, but that breaks the existing SessionData typing :(

I will continue to investigate when I next get some time

@eiskalteschatten
Copy link

I'm also having this issue which is preventing me from updating...

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

No branches or pull requests

4 participants