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 TS2351: This expression is not constructable. #37

Open
guidev opened this issue Jan 29, 2024 · 2 comments
Open

error TS2351: This expression is not constructable. #37

guidev opened this issue Jan 29, 2024 · 2 comments

Comments

@guidev
Copy link

guidev commented Jan 29, 2024

I get the following error when trying to use it with typescript:

error TS2351: This expression is not constructable.
  Type 'typeof import("/Users/guiguiguigui93/Progetti/aibattle/node_modules/passport-magic-login/dist/index")' has no construct signatures.

my code

const magicLogin = new MagicLoginStrategy({
    secret: process.env.MAGIC_LINK_SECRET,
    callbackUrl: "/auth/magiclogin/callback",
    sendMagicLink: async (destination, href) => {
        console.log("sendMagicLink", destination, href);
    },
    verify: (payload, callback) => {
        console.log("verify", payload);
    },
    jwtOptions: {
        expiresIn: "2 days",
    }
})

@aarhusgregersen
Copy link

aarhusgregersen commented Apr 3, 2024

Heya!

I'm getting the exact same thing during a conversion from CJS to ESM.
I suspect it has to do with the way imports are handled in ESM, but that's about all I know about it.

Are you using CJS or ESM, @guidev ?
Additionally, did you manage to find a solution or workaround?

If not I would think that the "trick" that works for some of the other strategy packages would work:
const MagicLoginStrategy = require("passport-magic-login").Strategy

Do note I haven't tested or verified this, it's just something I suspect might work

@aarhusgregersen
Copy link

After a bit of googling it turns out there is an answer for this:
Simply do:

import MagicLoginStrategy from "passport-magic-login";

const magicLogin = new MagicLoginStrategy.default();

https://stackoverflow.com/a/72676003/5065467

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

2 participants