builder icon indicating copy to clipboard operation
builder copied to clipboard

Using Next.js App Dir with Builder V2

Open RobSchilderr opened this issue 1 year ago • 6 comments

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

  • Being able to use App Router and Pages Router with Builder V2
  • Being able to register components, only client side components is okay.

Additional context

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

RobSchilderr avatar Apr 24 '24 12:04 RobSchilderr

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';

khiemtong avatar Apr 25 '24 13:04 khiemtong

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.

samijaber avatar Apr 25 '24 17:04 samijaber

@samijaber @omspacecode this bug appears to be stale, and I have observed that the omission of the vm-runtime config does not prevent me from using the dependency. I also noted some changes to the dependencies specific to this feature in latter releases....

Thoughts?

jaydubb12 avatar Jun 25 '24 16:06 jaydubb12

@jaydubb12 the initializeNodeRuntime function is only needed for certain production Node.js environments (such as Vercel) which tend to apply additional bundling steps that may remove sub-dependencies from the server bundle (such as isolated-vm in this case).

If your production environment is not running into any errors, then this means it does not need initializeNodeRuntime and you are free to ignore it.

samijaber avatar Jun 26 '24 20:06 samijaber

@samijaber good to hear. The challenge is, we need to be able to build it locally...and that is currently the challenge I have also run into.

The issue appears to be a file resolution problem during build time.

jaydubb12 avatar Jun 26 '24 22:06 jaydubb12

@jaydubb12 I am not following. What issue are you encountering exactly? Please provide a detailed breakdown with error logs and how you've integrated the SDK.

If your issue is unrelated to the one discussed here, please open a separate Github Issue to track it.

samijaber avatar Jun 27 '24 19:06 samijaber

Closing this issue as the types declaration problem has been fixed already.

samijaber avatar Oct 02 '24 14:10 samijaber