Skip to content

Commit ca1da40

Browse files
committed
fix: ensure compat with [email protected]
Closes #887
1 parent 3450b71 commit ca1da40

File tree

3 files changed

+177
-117
lines changed

3 files changed

+177
-117
lines changed

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import type { NextApiHandler } from 'next';
88
import type { Server, IncomingMessage, ServerResponse } from 'http';
99
import type { RequestInit, Response as FetchReturnValue } from 'node-fetch';
1010

11-
// @ts-ignore: ignore this (conditional) import so bundlers don't choke and die
12-
import type { apiResolver as NextApiResolver } from 'next/dist/server/api-utils/node';
11+
import type { apiResolver as NextApiResolver } from 'next/dist/server/api-utils/node/api-resolver';
1312

1413
/**
1514
* This function is responsible for adding the headers sent along with every
@@ -166,9 +165,10 @@ export async function testApiHandler<NextResponseJsonType = any>({
166165

167166
try {
168167
if (!apiResolver) {
169-
// ? The following is for next@>=12.1.0:
170-
// @ts-ignore: conditional import for earlier next versions
171-
({ apiResolver } = await import('next/dist/server/api-utils/node.js')
168+
// ? The following is for next@>=12.5.4:
169+
({ apiResolver } = await import('next/dist/server/api-utils/node/api-resolver.js')
170+
// ? The following is for next@<12.5.4 >=12.1.0:
171+
.catch(tryImport('next/dist/server/api-utils/node.js'))
172172
// ? The following is for next@<12.1.0 >=11.1.0:
173173
.catch(tryImport('next/dist/server/api-utils.js'))
174174
// ? The following is for next@<11.1.0 >=9.0.6:

test/integration-client-next.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ const NEXT_VERSIONS_UNDER_TEST = satisfiesRange(process.versions.node, '<15') ?
2828
['next@^10', 'react@^17'],
2929
['[email protected]', 'react@^17'],
3030
['next@^11', 'react@^17'],
31-
['[email protected]', 'react@^17'],
32-
['next@latest', 'react@^17']
31+
['[email protected]', 'react@^18'],
32+
['[email protected]', 'react@^18'],
33+
['next@latest', 'react@^18']
3334
]
3435
:
3536
[
@@ -41,6 +42,7 @@ const NEXT_VERSIONS_UNDER_TEST = satisfiesRange(process.versions.node, '<15') ?
4142
['[email protected]'], // ? See issue #295
4243
['next@^11'], // ? Latest version 11 release
4344
['next@^12.0.x'], // ? See issue #487
45+
['next@^13.5.3'], // ? See issue #887
4446
['next@latest'] // ? Latest release
4547
];
4648

0 commit comments

Comments
 (0)