builder
builder copied to clipboard
Error when running in latest Next.js version with middleware
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.
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
?
This issue also happens if you try to run Next.js with server components. That one is harder to work around.
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?
Running a hydrogen storefront using vercel's edge functions
Same issue running a hydrogen storefront on vercel's edge functions.
This should be really looked into asap, same issue over here
This is fixed and released in the latest stable version please use @builder.io/[email protected]
to get the fix, thank you for reporting