Closed DaveStein closed 2 years ago
PS: I just realized Next11 is only a couple weeks old
PS: I just realized Next11 is only a couple weeks old
I get the same on 10.2.3
@DaveStein Not sure if you've got auth0
package installed? I notice I only get this if I install that package. If I remove it, it goes away.
Example Sandbox https://codesandbox.io/s/zo9bl?file=/pages/index.tsx
I don't have auth0
anywhere in my package-lock.json
so maybe it's some dependency of that we both have?
I'm having this issue as well. Removing @auth0/nextjs-auth0
didn't fix it for me.
same here
I'm also seeing this issue with next
10.2.3 and node-mocks-http
1.10.0 (as 1.11.0 is not on the Yarn registry yet).
Has anyone found a way to resolve this issue?
The error I'm seeing is very slightly different in terms of number of missing properties:
Type 'NextApiRequest' does not satisfy the constraint 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'.
Type 'NextApiRequest' is missing the following properties from type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>': get, header, accepts, acceptsCharsets, and 23 more.
Type 'ServerResponse & { send: Send<any>; json: Send<any>; status: (statusCode: number) => NextApiResponse<any>; redirect(url: string): NextApiResponse<...>; redirect(status: number, url: string): NextApiResponse<...>; setPreviewData: (data: string | object, options?: { ...; }) => NextApiResponse<...>; clearPreviewData: (...' is missing the following properties from type 'Response<any, Record<string, any>>': sendStatus, links, jsonp, sendFile, and 18 more.
This happened to me when I installed a package that had specified @types/express
as its dependency.
The issue is that createMocks
requires an express.Request
as the first generic argument, so when the types for that suddenly exist, NextApiRequest
is then not a valid argument for it. Since while express.Request
and NextApiRequest
both extend Node's http.IncomingMessage
, they are not compatible with each other.
I fixed this locally like this:
import { createMocks as _createMocks } from 'node-mocks-http';
import type { RequestOptions, ResponseOptions } from 'node-mocks-http';
const createMocks = _createMocks as (
reqOptions?: RequestOptions,
resOptions?: ResponseOptions,
// @ts-ignore: Fixing this: https://github.com/howardabrams/node-mocks-http/issues/245
) => Mocks<NextApiRequest, NextApiResponse>;
...
const { req, res } = createMocks({
method: 'GET',
});
// Check types by hovering:
// const req: MockRequest<NextApiRequest>
// const res: MockResponse<NextApiResponse<any>>
Stale issue message
Not stale.
Should not be closed.
Stale issue message
I still have this issue in combination with iron-session. Should not be closed.
This should be reopened.
For those that are seeing this because they have typing issue, check this out https://github.com/howardabrams/node-mocks-http/issues/255#issuecomment-1136674043 Typing union is the key.
Just found your repo over here: https://stackoverflow.com/questions/62230808/test-nextjs-api-middleware-with-jest
I did
httpMocks.createRequest<NextApiRequest>();
andhttpMocks.createResponse<NextApiRequest>();
but TS complains. Does this repo need an update or am I doing something wrong? I'm currently on Next11.0.1