fastify-passport: fastifyPassport.initialize is not a function

🐛 Bug Report

A clear and concise description of what the bug is.

To Reproduce

Steps to reproduce the behavior:

// Paste your code here
const fastify = require('fastify')();
const fastifyPassport= require('fastify-passport')
const fastifySecureSession= require('fastify-secure-session')
// set up secure sessions for fastify-passport to store data in
fastify.register(fastifySecureSession, { key: fs.readFileSync(path.join(__dirname, "secret-key")) });
// initialize fastify-passport and connect it to the secure-session storage. Note: both of these plugins are mandatory.
fastify.register(fastifyPassport.initialize());
fastify.register(fastifyPassport.secureSession());
console.log(fastifyPassport);

Error FastifyPassport.initialize is not a function

image

Expected behavior

A clear and concise description of what you expected to happen.

fastifyPassport.initialize should initialize passport
also on same note when someone console `fastifyPassport`
below appears
{
  Strategy: [Getter],
  default: Authenticator {
    key: 'passport',
    userProperty: 'user',
    strategies: { session: [SessionStrategy] },
    serializers: [],
    deserializers: [],
    infoTransformers: [],
    sessionManager: SecureSessionManager {
      key: 'passport',
      serializeUser: [Function: bound serializeUser] AsyncFunction
    }
  }
}

Your Environment

  • node version: v14.15.1
  • fastify version: >=^3.9.1
  • os: windows-wsl-ubuntu

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 17 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Yes, there are 2 viable solutions:

  1. adding a “js bridge file” since TS explicitly doesn’t support this functionality. (it leaves only .default prop if export default is used)
  2. adding namedExport and let the users use a named one in the contexts that don’t support .default property (CJS and older Node.js versions mainly)

@Melodyn I’ve just seen that your file is a .js one, so you are not using any esModuleInterop: true since your context is a CJS context and your case is the same as @matt212 one. In fact, your fix is just to add .default.

Thanks for the bug report. Super weird. Which version of fastify-passport are you experiencing this on?