Skip to content

Unable to intercept requests sent during pre-rendering in Next.js #1340

@ajfAfg

Description

@ajfAfg

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 14 or higher

Node.js version

v18.3.0

Reproduction repository

https://github.com/ajfAfg/msw-operation-research

Reproduction steps

  1. Run the following commands
git clone https://github.com/ajfAfg/msw-operation-research.git
cd msw-operation-research/nextjs-rest
npm install
npm run dev
  1. Open http://localhost:3000

Current behavior

In src/pages/index.tsx, getServerSideProps fetches data and outputs the received data to the console. Currently, the output is as follows.

server: {"answer":"yes","forced":false,"image":"https://yesno.wtf/assets/yes/14-b57c6dc03aa15a4b18f53eb50d6197ee.gif"}

The data being fetched here is as follows.

$ curl https://yesno.wtf/api
{"answer":"yes","forced":false,"image":"https://yesno.wtf/assets/yes/11-a23cbde4ae018bbda812d2d8b2b8fc6c.gif"}

Expected behavior

The expected output is as follows, since the request is intercepted by the definition in src/mocks/handlers.ts.

server: {"foo":"bar"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds:triageIssues that have not been investigated yet.scope:nodeRelated to MSW running in Node

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions