teamhanko / hanko

Authentication and user management system optimized for passkeys

Home Page:https://hanko.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SyntaxError: Unexpected token 'export' in Nextjs

Astrak opened this issue · comments

Checklist

  • I could not find a solution in the existing issues or docs.
  • I agree to follow this project's Code of Conduct.

Describe the bug

I'm in a NextJS/Typescript project. I can't run my app when adding the <hanko-auth/> component, compilation fails with SyntaxError: Unexpected token 'export' in node_modules/@teamhanko/hanko-elements/dist/elements.js

Likely the compilation target is wrong. In tsconfig.json it is "target": "es2017". But if I change it to es6 or es5 it's the same.

The error is identical to what is described in #905.

If I create a new next project from scratch, it doesn't happen. So I try to replicate the compilation issue in the new one, in the hope of spotting the problem: If I copy/paste my current tsconfig.json, from the project where it fails, to the new working nextjs implementation, it still works, so that typescript compilation configuration is not at fault.

The only other custom configuration I have is in next.config.js but I can do the same, copy paste it into the working project, and it still works.

I am not finding where the compilation error lies.

Reproducing the bug

I cannot manage to reproduce it from a new next project with typescript.

Logs

Server Error
SyntaxError: Unexpected token 'export'

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
<unknown>
(...)/node_modules/.pnpm/ (teamhanko+hanko-elements@0.8.3/node_modules/@teamhanko/hanko-elements/dist/elements.js (2)

Configuration

No response

Hanko Version

v0.8.3

OS Hanko Backend

Linux

OS Version Hanko Backend

No response

OS

Linux

OS Version

No response

Browser Version

No response

Environment

None

Additional Context

No response

Turns out I was copying a raw nextjs repo where it worked without the dynamic import, which is what I needed to make it work in my current nextjs repo. I don't know why it worked without in the test one, but this is what fixed it.