Next.js Discord

Discord Forum

Next.js Build Error with Ably + serverComponentsExternalPackages

Unanswered
Asian black bear posted this in #help-forum
Open in Discord
Asian black bearOP
Build fails with "Element type is invalid" error when using serverComponentsExternalPackages: ["ably"] in next.config.js

Details:
- Next.js 14.2.29 App Router
- Works fine in dev (npm run dev)
- Fails during build (npm run build) with prerender errors
- Even with ALL Ably code commented out, just having the config breaks the build

Config:
// next.config.js
experimental: {
  serverComponentsExternalPackages: ["ably"]
}


Error:
Error occurred prerendering pages.
Element type is invalid: expected a string (for built-in components)
or a class/function (for composite components) but got: undefined.

2 Replies

ably components should be dynamic imported
@chisto ably components should be dynamic imported
Asian black bearOP
I've done all that, with ssr false and all the best practices, that's why I mentioned everything is working well in dev mode with no warnings no errors but in build it brakes with this error