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

dynamic import() does not work #47

Closed
slavonicsniper opened this issue Nov 25, 2022 · 1 comment
Closed

dynamic import() does not work #47

slavonicsniper opened this issue Nov 25, 2022 · 1 comment

Comments

@slavonicsniper
Copy link

Describe the Issue

As I currently cannot import the package in our nx based project because of Error [ERR_REQUIRE_ESM]: require() of ES Module not supported. I wanted to use a dynamic import to load the package but it looks like it does not work neither.
const { verify } = import('azure-ad-verify-token');
console.log(verify) -> { default: {} }

Todo

Expected behavior

dynamic import loads the package correctly

Todo

Steps to Reproduce

npm install azure-ad-verify-token
const { verify } = import('azure-ad-verify-token');
verify() -> verify is not a function

n/a

Other Information

n/a

@justinlettau
Copy link
Owner

Dynamic imports are asynchronous (see here). So you'll need to use .then() or await like this:

async function main() {
  const { verify } = await import('azure-ad-verify-token');

  try {
    await verify(myToken, {
      jwksUri: process.env.JWKS_URI,
      issuer: process.env.ISSUER,
      audience: process.env.AUDIENCE,
    });
  } catch (error) {
    console.log(error);
  }
}

If you have issues with that, feel free to reopen, thanks.

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