builder icon indicating copy to clipboard operation
builder copied to clipboard

Error when running in latest Next.js version with middleware

Open kevva opened this issue 3 years ago • 4 comments

On Next.js v12, you'll get this when adding middleware to your app:

`eval` not allowed in Middleware pages/_middleware
error - node_modules/@builder.io/sdk/dist/index.esm.js?b22a (919:0) @ <unknown>
TypeError: Cannot read property 'parse' of null

This points to this line which makes use of serverOnlyRequire. The problem is that that function makes use of eval to detect require and since Next.js doesn't allow eval in middleware it'll throw no matter what so I think another non-eval check is needed.

kevva avatar Oct 31 '21 13:10 kevva

This happens because I import somethings that imports @builder/react in my middleware. If I remove that import or convert it to a dynamic import it works so I can work around it. But regardless, maybe there's a better alternative to using eval?

kevva avatar Oct 31 '21 14:10 kevva

This issue also happens if you try to run Next.js with server components. That one is harder to work around.

kevva avatar Nov 04 '21 11:11 kevva

Hi @kevva thanks for reporting this issue, do you have any kind of reproduction steps for the issue with nextjs server components?

For the middleware it looks like it's a hard limit as it only support a subset of nodejs API, what's the use case for using the react sdk in the middleware function?

teleaziz avatar Nov 08 '21 17:11 teleaziz

Running a hydrogen storefront using vercel's edge functions

end0cr1ne avatar Aug 06 '22 10:08 end0cr1ne

Same issue running a hydrogen storefront on vercel's edge functions.

rista404 avatar Aug 17 '22 21:08 rista404

This should be really looked into asap, same issue over here

terza98 avatar Aug 18 '22 05:08 terza98

This is fixed and released in the latest stable version please use @builder.io/[email protected] to get the fix, thank you for reporting

teleaziz avatar Sep 09 '22 17:09 teleaziz