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

2.4.0 Main entry point still exports handlers (i.e: GraphQLHandler) #2247

Closed
4 tasks done
nartc opened this issue Aug 29, 2024 · 5 comments · Fixed by #2250
Closed
4 tasks done

2.4.0 Main entry point still exports handlers (i.e: GraphQLHandler) #2247

nartc opened this issue Aug 29, 2024 · 5 comments · Fixed by #2250
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@nartc
Copy link

nartc commented Aug 29, 2024

Prerequisites

Environment check

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

Node.js version

20.14.0

Reproduction repository

https://github.com/nartc/msw-entry-point-bug

Reproduction steps

npm install
npm test

Script fails with Cannot find module "graphql"

Current behavior

Thank you for your effort on msw.

Before I say anything, I believe our issue is our own "user error". However, I also believe this issue can still be an overlook as current code would break at runtime with 2.4.0 and the release note does not mention anything about the new secondary entry points available in 2.4.0

import { http, HttpHandler } from 'msw';

This works in pre 2.4.0 but will break in 2.4.0 for projects that don't have graphql installed. This is due to msw core entry point still exports the handlers which makes graphql NOT an optional peer dependency.

The proper fix would be to import from msw/core/http but it seems like msw/core/http does not export HttpHandler either.

Once again, our project runs into this due to many errors/mistakes on our part but I want to raise this issue in case others run into the same thing (or have the same user errors/mistakes)

Expected behavior

import { http } from 'msw';

This import should at least break at compilation time (type checking time) with something like: msw does not export http. And release note should mention migrating to msw/core/http (or respective entry point for the handlers).

@nartc nartc added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Aug 29, 2024
@nartc nartc changed the title Main entry point still exports handlers (i.e: GraphQLHandler) 2.4.0 Main entry point still exports handlers (i.e: GraphQLHandler) Aug 29, 2024
@ghost91-
Copy link

Unfortunately, using more specific exports doesn't always seem to be possible. For example, unless I am mistaken, delay is only exported via the main export.

Similarly, HttpResponse also is not exported from msw/core/http. Probably applies to quite a few more things.

If msw/core/http is really intended as the "don't need graphql" entrypoint, the exports should probably be identical to those of msw, except from the graphql related stuff.

@nartc
Copy link
Author

nartc commented Aug 29, 2024

@ghost91- or msw entry point should be cleared of anything that requires optional peer dependencies so things like main utilities can still be exported from the main entry point.

@kettanaito
Copy link
Member

@ghost91-, good point. The explicit import would be better once we drop graphql export from the root module. So you import graphl from msw/core/graphql only.

For now, I think the safest way to fix this and now force developers to install graphql is to make that import dynamic. Need to give this a try.

@kettanaito
Copy link
Member

I will close this one in favor of #2248 (has a more searchable error message). Please keep track of the updates there. Thanks.

@kettanaito
Copy link
Member

Released: v2.4.1 🎉

This has been released in v2.4.1!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

@github-actions github-actions bot locked and limited conversation to collaborators Oct 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
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

Successfully merging a pull request may close this issue.

3 participants