Can't use couchbase 4.3.1 npm module with Next.js in a Nx managed monorepo

After quite a bit of digging, I found the issue. Since the Couchbase package is a native module, it must be marked as external in Webpack.

I found a similar problem with Bcrypt Fails in Next.js app/ directory incl. with API Route Handlers #979

Here is what I ended up putting in my next.config.cjs

const nextConfig = {
  webpack: (config) => {
    config.externals = [...config.externals, 'couchbase'];
    return config;
  },
};

module.exports = nextConfig;

Also, Couchbase needs to be loaded with require, not import.

1 Like