MasterKale / SimpleWebAuthn

WebAuthn, Simplified. A collection of TypeScript-first libraries for simpler WebAuthn integration. Supports modern browsers, Node, Deno, and more.
https://simplewebauthn.dev
MIT License
1.63k stars 137 forks source link

SyntaxError: Unexpected token 'export' #168

Closed aircliff01 closed 2 years ago

aircliff01 commented 2 years ago

I'm running into this error while using it in next.js. When I changed this line simplewebauthn/browser/dist/bundle/index.js (123) from exports { browserSupportsWebauthn, platformAuthenticatorIsAvailable, startAuthentication, startRegistration }; to module.exports = { browserSupportsWebauthn, platformAuthenticatorIsAvailable, startAuthentication, startRegistration }; then it works fine. Not sure if its related to your tsconfig target or not. I tried adjusting my tsconfig file to different target and module output but none worked.

Screen Shot 2021-12-28 at 10 24 36 PM

im using nextjs.

below is my tsconfig:

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}
akanass commented 2 years ago

Hi @aircliff thanks for using this project.

To answer to your problem, you can see the previous issue #136 and the miracle will be there :)

All is in ESM in this project and Nexts.js is in CJS so you have to transpile by your own.

MasterKale commented 2 years ago

Hello @aircliff, that issue ran a bit long so here's a link directly to that issue's solution. Can you try that and let me know how it goes?

https://github.com/MasterKale/SimpleWebAuthn/issues/136#issuecomment-893506455

aircliff01 commented 2 years ago

Well y'all are super fast with your response 🤟 . I checked the linked issue and abracadabra there lies the solution, works like magic 🎉 thanks @MasterKale @akanass I will close this issue. Sorry for the duplicate.