BuilderIO / builder

Drag and drop headless CMS for React, Vue, Svelte, Qwik, and more
https://builder.io
MIT License
6.77k stars 840 forks source link

Using Next.js App Dir with Builder V2 #3235

Open RobSchilderr opened 3 weeks ago

RobSchilderr commented 3 weeks ago

Describe the bug In this example, provided by Builder.io, it is suggested to use the following code snippet:

  const { initializeNodeRuntime } = await import('@builder.io/sdk-react/node/init');
  initializeNodeRuntime();

However, initializeNodeRuntime does not seem to exist within the module, as evidenced by the following error screenshot:

Screenshot 2024-04-24 at 13 06 51

This issue occurs despite following the recommended setup. I would prefer to use this package due to its compatibility with the pages router in my project, which precludes using the Next.js SDK.

Additionally, I attempted to use the directive 'use client' at the top of the file to handle client-side custom components, but this approach failed to resolve the issue.

To Reproduce Steps to reproduce the behavior:

  1. Initialize a new Next.js project (version 13.4.8) configured with the app router.
  2. Attempt to import initializeNodeRuntime as specified.
  3. Observe the error indicating that initializeNodeRuntime cannot be found.

Expected behavior

Additional context

Using Next.js version 13.4.8 and following the guide provided in the Builder.io GitHub repository.

khiemtong commented 3 weeks ago

We ran into this (we're on NextJS 14.1) following the same instructions, the workaround is to manually declare the module (it is there in the package just not declared?)

Add something like decs.d.ts to your root

declare module '@builder.io/sdk-react/node/init';
samijaber commented 3 weeks ago

Yes, there is an issue with the types not propagating correctly for certain TS configurations. We will investigate this, thanks for reporting.

The import itself should work correctly on the JS side.