Skip to content

Commit 0887243

Browse files
fix(backend): Support NextJS 14 (clerk#1948)
* fix(backend): Fix for next 14 fetch bind issue * fix(nextjs): Use named imports for fetch runtime polyfill Next14 seems to have changed the way it handles default exports when using the webpack bundler for some of their build variants when using `npm run dev`. This commit ensures that we no longer use the default export in an effort to improve compat between the different nextjs versions. More information can be found here: https://esbuild.github.io/content-types/#default-interop and here: clerk#612 * Create late-dolphins-peel.md --------- Co-authored-by: Nikos Douvlis <nikosdouvlis@gmail.com>
1 parent 2232008 commit 0887243

4 files changed

Lines changed: 9 additions & 2 deletions

File tree

.changeset/late-dolphins-peel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clerk/backend": minor
3+
---
4+
5+
Add support for NextJS 14

packages/backend/src/runtime/browser/fetch.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ export const RuntimeHeaders = Headers;
55
export const RuntimeRequest = Request;
66
export const RuntimeResponse = Response;
77
export const RuntimeAbortController = AbortController;
8+
export const RuntimeFetch = fetch;

packages/backend/src/runtime/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import crypto from '#crypto';
1818
import * as fetchApisPolyfill from '#fetch';
1919

2020
const {
21-
default: fetch,
21+
RuntimeFetch,
2222
RuntimeAbortController,
2323
RuntimeBlob,
2424
RuntimeFormData,
@@ -44,7 +44,7 @@ type Runtime = {
4444
// The globalThis object is supported for Node >= 12.0.
4545
//
4646
// https://github.com/supabase/supabase/issues/4417
47-
const globalFetch = fetch.bind(globalThis);
47+
const globalFetch = RuntimeFetch.bind(globalThis);
4848
// DO NOT CHANGE: Runtime needs to be imported as a default export so that we can stub its dependencies with Sinon.js
4949
// For more information refer to https://sinonjs.org/how-to/stub-dependency/
5050
const runtime: Runtime = {

packages/backend/src/runtime/node/fetch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ module.exports.RuntimeHeaders = Headers;
88
module.exports.RuntimeRequest = Request;
99
module.exports.RuntimeResponse = Response;
1010
module.exports.RuntimeAbortController = AbortController;
11+
module.exports.RuntimeFetch = fetch;

0 commit comments

Comments
 (0)