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

CustomEvent is not defined #1020

Closed
2 tasks done
ha-sante opened this issue Sep 12, 2023 · 7 comments
Closed
2 tasks done

CustomEvent is not defined #1020

ha-sante opened this issue Sep 12, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@ha-sante
Copy link

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

  • error node_modules@teamhanko\hanko-frontend-sdk\dist\sdk.modern.js (1:4914) @ eval
  • error ReferenceError: CustomEvent is not defined

Using the "@teamhanko/hanko-frontend-sdk": "^0.8.0", in "next": "13.4.7",

Reproducing the bug

I'd reckon how to reproduce this error is to

  1. Init a nextjs app with versioning 13.4.7
  2. Install the "@teamhanko/hanko-frontend-sdk": "^0.8.0",
  3. Init the hanko client provided by the frontend sdk
  4. Try to use the passcode feature
  5. You will see this error on import and usage.
  6. My current impression is that on import it's expecting some core browser features in turn resulting in the error (nextjs 13 has moved to server first which further contributes to this)

Logs

`- error node_modules\@teamhanko\hanko-frontend-sdk\dist\sdk.modern.js (1:4914) @ eval
- error ReferenceError: CustomEvent is not defined
    at __webpack_require__ (direcotorypathtothisfolder\.next\server\webpack-runtime.js:33:43)
    at eval (./src/lib/file.tsx:53:87)
    at (sc_client)/./src/lib/file.tsx (direcotorypathtothisfolder\.next\server\app\(dashboard)\path\page.js:16256:1)
    at __webpack_require__ (direcotorypathtothisfolder\.next\server\webpack-runtime.js:33:43)
    at eval (./src/app/error.tsx:10:68)
    at (sc_client)/./src/app/error.tsx (direcotorypathtothisfolder\.next\server\app\(dashboard)\path\page.js:16201:1)
    at __webpack_require__ (direcotorypathtothisfolder\.next\server\webpack-runtime.js:33:43)
    at JSON.parse (<anonymous>)`

Configuration

No response

Hanko Version

0.8.0

OS Hanko Backend

None

OS Version Hanko Backend

No response

OS

None

OS Version

No response

Browser Version

Chrome

Environment

None

Additional Context

No response

@ha-sante ha-sante added the bug Something isn't working label Sep 12, 2023
@github-project-automation github-project-automation bot moved this to 🆕 New in Hanko Sep 12, 2023
@lfleischmann
Copy link
Member

Hi @ha-sante,

My current impression is that on import it's expecting some core browser features in turn resulting in the error (nextjs 13 has moved to server first which further contributes to this)

Yes that is correct. The SDK includes a class that extends the CustomEvent API.

Does the error stop your app from working entirely or is it "just" an SSR error?

If it is the former, you could try a dynamic import similar to what is shown in the docs for hanko-elements (see lines 12-18 for the App directory code example) - but import the hanko-frontend-sdk instead:

  const [hanko, setHanko] = useState<Hanko>();

  useEffect(() => {
    import("@teamhanko/hanko-frontend-sdk").then(({ Hanko }) =>
      setHanko(new Hanko(hankoApi))
    );
  }, []);

Alternatively, you could also try using next/dynamic.

@ha-sante
Copy link
Author

Will look into this @lfleischmann and report back

@ELGBJQ2Y3126122
Copy link

Your most welcome

@amjed-ali-k
Copy link
Contributor

adding force-dynamic Route Segment Config to the page fixes this issue for me.

// layout.tsx | page.tsx | route.ts
export const dynamic = "force-dynamic";

@sojinsamuel
Copy link
Contributor

adding force-dynamic Route Segment Config to the page fixes this issue for me.

// layout.tsx | page.tsx | route.ts
export const dynamic = "force-dynamic";

I tried to add the route config in the root layout, but didnt work. The error in the console is annoying

@Ashutosh-Bhadauriya
Copy link
Contributor

Ashutosh-Bhadauriya commented Oct 20, 2023

Hey @sojinsamuel this issue has been fixed, we need to dynamic import the component where we use it. We'll be updating the docs soon

import dynamic from 'next/dynamic';
const HankoAuth = dynamic(() => import('@/components/HankoAuth'), { ssr: false })

export default function LoginPage() {
 return (
   <HankoAuth />
 );
}

@Ashutosh-Bhadauriya
Copy link
Contributor

Closing this, as the issue has been addressed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Archived in project
Development

No branches or pull requests

6 participants