Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find module 'msw/node' in Jest test after upgrading to v2 #1787

Closed
4 tasks done
mbaumanndev opened this issue Oct 23, 2023 · 2 comments
Closed
4 tasks done

Cannot find module 'msw/node' in Jest test after upgrading to v2 #1787

mbaumanndev opened this issue Oct 23, 2023 · 2 comments
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@mbaumanndev
Copy link

Prerequisites

Environment check

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

Node.js version

v18.14.2

Reproduction repository

https://github.com/mbaumanndev/msw-issue-repro

Reproduction steps

On the repo:

yarn install --immutable
yarn test

Importing msw/node cause an error in Jest.

Note that this is an extract from my dev env on a project where it was working with msw 1.3.2 and where I followed the upgrade guide.

Current behavior

Test suite failed to run

    Cannot find module 'msw/node' from 'src/jestUtils.ts'

    Require stack:
      src/jestUtils.ts
      src/sample.test.tsx

      1 | import { DefaultBodyType, Path, PathParams, ResponseResolver, http } from 'msw'
    > 2 | import { setupServer } from 'msw/node'
        | ^
      3 | import { HttpRequestResolverExtras } from 'msw/lib/core/handlers/HttpHandler'
      4 |
      5 | export interface ServerEndoint {

      at Resolver._throwModNotFoundError (node_modules/jest-resolve/build/resolver.js:427:11)
      at Object.require (src/jestUtils.ts:2:1)
      at Object.require (src/sample.test.tsx:2:1)

Test Suites: 1 failed, 1 passed, 2 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        0.867 s, estimated 1 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Expected behavior

The test should pass since Jest should be able to import msw/node

@mbaumanndev mbaumanndev added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Oct 23, 2023
@mbaumanndev
Copy link
Author

Related to #1786

@kettanaito
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node
Projects
None yet
Development

No branches or pull requests

2 participants