Module not found: Can't resolve 'http' after upgrading to Next.js 15 when using chargebee
Description of the Bug
After upgrading my project from Next.js v14 to v15, I encountered a module resolution error when trying to use the chargebee package. The issue appears to stem from importing Node.js core modules (http, https) in a file that is being bundled for the browser.
This error occurs both in my upgraded project and in a fresh Next.js v15 app with just chargebee installed.
Steps to reproduce
- Create a NextJS app with the latest version
- Install chargebee
- Create a route.ts file
- Inside the route.ts file, import chargebee and try to fetch something.
Expected Behavior
Chargebee works with NextJS 15
Operating System
macOS
Language version
NextJS
Library version
15.3.1
Additional context
No response
Hi @andreiDobai94, may I know what version of chargebee-node and what version of NodeJs you are using? I am not able to reproduce this in the following configuration.
{
"name": "cb-next-app",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "next dev --turbopack",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"chargebee": "^3.6.1",
"next": "15.3.1",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
"@tailwindcss/postcss": "^4",
"@types/node": "^20",
"@types/react": "^19",
"@types/react-dom": "^19",
"eslint": "^9",
"eslint-config-next": "15.3.1",
"tailwindcss": "^4",
"typescript": "^5"
}
}
The only difference is that I was not running the app with --turbopack.
I added turbopack and now it seems to work as expected.
Hi @andreiDobai94 thanks for the reply, we'll check why that is the case with --turbopack and get back.
@cb-alish Do you have an update on this? It is blocking our Upgrade to Next15 as well.
Tried chargebee 3.7.0 - 3.9.0.
Hi @JanThiel,
Thanks for reaching out, and sorry for the late reply. I tried to reproduce the issue on my end using the setup I mentioned, but everything works fine for me — even with the --turbopack option.
To help narrow this down, I need to know:
- Are you using
--turbopackoption? - What exact version of Next.js are you using?
- What Node.js version are you using?
- What OS are you on?
Would you be able to share the minimal implementation code that you are using?
Thanks!
Hi @cb-alish, we did some more digging on our end and figured out that his is unrelated to the NextJS update (at least in our case).
We upgraded from Chargebee 3.5.0 to the later versions. Our runtime environment is Cloudflare Pages which still requires the "Edge" runtime of NextJS. It seems you added several libraries (back) to the Chargebee SDK that renders it unusable on Edge runtimes. Explicitly (but maybe not the complete list) http, https, and crypto.
These libraries do not exist on the Edge runtime. That's why the build fails on Cloudflare. But it does not fail locally when you run it with a NodeJS environment.
Hi @JanThiel, appreciate you putting in all the effort. Just to confirm—was it working for you up until v3.5.0? Apologies for the trouble. We'll definitely look into it and aim to make the library platform-agnostic.
I can confirm that 3.5.0 does work. 3.7 and upwards do not work anymore.
We did not test 3.6.
Chargebee 3.6.1 does work. Just tested. 3.7.0 started to fail. I believe it might be part of the retry handling you added. But I did not check the Changelog again when you added that.
We today tested using Chargebee 3.6.1, 3.5.0 and 3.4.0 with Next15 on Cloudflare Pages and all three version fail with the https and http packages missing.
On Next14 Chargebee 3.6.1 works and it stars to fail because of crypto with Chargebee 3.7.0.
In any way, you should remove the dependencies to this libs to allow a full Edge runtime support. Do you have any timeline for this? Asking because if not or too far out, we would (again) fork the CB SDK and remove the libraries ourselves to unblock our NextJS update.
For reference here is the output of the Cloudflare Pages Build with NextJS 15 and Chargebee 3.5.0:
15:02:49.495 | ▲ Creating an optimized production build ...
-- | --
15:03:11.636 | ▲ Failed to compile.
15:03:11.636 | ▲ ./node_modules/.pnpm/[email protected]/node_modules/chargebee/esm/net/NodeClient.js:2:1
15:03:11.637 | ▲ Module not found: Can't resolve 'http'
15:03:11.637 | ▲ 1 \| import { HttpClient, HttpClientResponse, } from './ClientInterface.js';
15:03:11.637 | ▲ > 2 \| import * as http from 'http';
15:03:11.637 | ▲ \| ^
15:03:11.637 | ▲ 3 \| import * as https from 'https';
15:03:11.637 | ▲ 4 \| export class NodeHttpClient extends HttpClient {
15:03:11.638 | ▲ 5 \| async makeApiRequest(props) {
15:03:11.638 | ▲
15:03:11.638 | ▲ https://nextjs.org/docs/messages/module-not-found
15:03:11.638 | ▲
15:03:11.638 | ▲ Import trace for requested module:
15:03:11.638 | ▲ ./node_modules/.pnpm/[email protected]/node_modules/chargebee/esm/chargebee.esm.js
15:03:11.638 | ▲ ./src/app/api/contacts/route.ts
15:03:11.638 | ▲ ./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/build/webpack/loaders/next-edge-app-route-loader/index.js?...
15:03:11.639 | ▲
15:03:11.639 | ▲ ./node_modules/.pnpm/[email protected]/node_modules/chargebee/esm/net/NodeClient.js:3:1
15:03:11.639 | ▲ Module not found: Can't resolve 'https'
15:03:11.639 | ▲ 1 \| import { HttpClient, HttpClientResponse, } from './ClientInterface.js';
15:03:11.639 | ▲ 2 \| import * as http from 'http';
15:03:11.639 | ▲ > 3 \| import * as https from 'https';
15:03:11.639 | ▲ \| ^
15:03:11.640 | ▲ 4 \| export class NodeHttpClient extends HttpClient {
15:03:11.640 | ▲ 5 \| async makeApiRequest(props) {
15:03:11.640 | ▲ 6 \| const protocol = props.protocol === 'http' ? http : https;
15:03:11.640 | ▲
15:03:11.640 | ▲ https://nextjs.org/docs/messages/module-not-found
15:03:11.640 | ▲
15:03:11.640 | ▲ Import trace for requested module:
15:03:11.640 | ▲ ./node_modules/.pnpm/[email protected]/node_modules/chargebee/esm/chargebee.esm.js
15:03:11.640 | ▲ ./src/app/api/contacts/route.ts
15:03:11.641 | ▲ ./node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/build/webpack/loaders/next-edge-app-route-loader/index.js?...
15:03:11.641 | ▲ > Build failed because of webpack errors
Hi @JanThiel, sorry for the delay. We are targeting to fix this within a week. Thanks for your patience.
No problem. Thank you very much for the quick response and resolution @cb-alish
Hi @JanThiel, sorry for the delay. We were planning to remove that module, but we want this to be a non-breaking change. So we've released a new beta version 3.12.0-beta.1, which is working for us locally in the edge environment. Could you please try it out and let us know if the issue still exists? We’ll make it a stable release once you confirm.
@cb-alish No problem at all :-) I can confirm that the Beta does provide a working build at Cloudflare Pages within an Edge runtime environment 🥳
Thank you very much for fixing it. Appreciate it!
Best Regards
Hi @JanThiel, this has been released in the stable version v3.12.0. We’re closing this issue, but please feel free to re-open if you continue to face any problems.