passwordless-id / webauthn

Webauthn / passkeys helper library to make your life easier. Client side, server side and demo included.
https://webauthn.passwordless.id
MIT License
454 stars 53 forks source link

Error: require() of ES Module - Instead change the require of index.js in applicationMutation.ts to a dynamic import() which is available in all CommonJS modules. #25

Closed alan345 closed 1 year ago

alan345 commented 1 year ago

Hello,

When in the backend (Express) with Typescript, I do this

npm install @passwordless-id/webauthn

then:

import { server } from '@passwordless-id/webauthn'
const applicationMutation = {
  createPasskeyApplication: async (_parent: unknown, args: Args, ctx: Ctx): Promise<Application> => {
     const registrationParsed = await server.verifyRegistration(args, expected)
  }
}

When I compile, I have this error:

[ERROR] 18:29:27 Error: require() of ES Module /Users/alan/Documents/app/backend/server/graphql/node_modules/@passwordless-id/webauthn/dist/esm/index.js from /Users/alan/Documents/app/backend/server/graphql/src/resolvers/mutation/applicationMutation.ts not supported.
Instead change the require of index.js in /Users/alan/Documents/app/backend/server/graphql/src/resolvers/mutation/applicationMutation.ts to a dynamic import() which is available in all CommonJS modules.
(node:22269) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023.

Any idea where this issue might come from? Thanks fro your help!

dagnelies commented 1 year ago

Too old target or node version perhaps?

dagnelies commented 1 year ago

Closed due to inactivity / insufficient information. You are welcome to re-open it with more details.

rogue-kitten commented 1 year ago

getting this same error in nestJS as well. @alan345 did you figure this out?

dagnelies commented 1 year ago

@rogue-kitten What's your node version?

rogue-kitten commented 1 year ago

it's the latest one, 20.7.0

neerosity commented 1 year ago

facing same issue I have node v 20+ https://github.com/passwordless-id/webauthn/issues/35

enri90 commented 10 months ago

Is it possible to use the build module in CommonJS?

dagnelies commented 9 months ago

See also https://github.com/passwordless-id/webauthn/issues/35#issuecomment-1900264705