ably-js icon indicating copy to clipboard operation
ably-js copied to clipboard

serverComponentsExternalPackages on Nextjs breaks production builds

Open Abdellah-Idrissi opened this issue 7 months ago • 5 comments

I'm facing an issue with Ably integration in Next.js App Router where I need serverComponentsExternalPackages: ["ably"] to stop this dev mode warning, related to this issue

⚠ ./node_modules/keyv/src/index.js
Critical dependency: the request of a dependency is an expression
Import trace for requested module:
./node_modules/keyv/src/index.js
./node_modules/cacheable-request/src/index.js
./node_modules/got/dist/source/core/index.js
./node_modules/got/dist/source/create.js
./node_modules/got/dist/source/index.js
./node_modules/ably/build/ably-node.js

and while adding serverComponentsExternalPackages: ["ably"] to next.config does solve these warnings I get another dev mode errors (non-breaking), and build errors (breaking)

  • dev error (non-breaking): Image

  • build error (breaking): Image

Current Implementation:

  • Using dynamic imports with ssr: false for Ably components
  • Getting Ably client from API route with authUrl: "/api"

Versions:

  • Next.js: 14.2.29
  • Ably: 2.9.0

┆Issue is synchronized with this Jira Task by Unito

Abdellah-Idrissi avatar Jun 06 '25 11:06 Abdellah-Idrissi

Hey @Abdellah-Idrissi, thank you for reporting the issue. From the error message, it seems that your app can’t resolve some of the imports. Could you provide a minimal reproducible example so we can take a closer look at the problem? You can also try updating Next to 15.x. The keyv package should be automatically opted out of bundling in the latest version of Next.js.

ttypic avatar Jun 09 '25 11:06 ttypic

@ttypic Thanks for the response!

Minimal repo: repo - reproduces the exact issues described Next.js 15: Unfortunately we can't upgrade to Next 15 currently due to project constraints, so we're stuck on 14.x.

Abdellah-Idrissi avatar Jun 10 '25 10:06 Abdellah-Idrissi

Thank you, @Abdellah-Idrissi. We’ll take a look and get back to you soon

ttypic avatar Jun 10 '25 10:06 ttypic

Well??

jimapl avatar Oct 27 '25 20:10 jimapl