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

tsc error: Cannot find module 'graphql' or its corresponding type declarations #1371

Closed
4 tasks done
irico3 opened this issue Aug 25, 2022 · 6 comments · Fixed by #1381
Closed
4 tasks done

tsc error: Cannot find module 'graphql' or its corresponding type declarations #1371

irico3 opened this issue Aug 25, 2022 · 6 comments · Fixed by #1381
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@irico3
Copy link

irico3 commented Aug 25, 2022

Prerequisites

Environment check

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

Node.js version

v16.11.0

Reproduction repository

https://github.com/takanokana/msw-for-issue

Reproduction steps

1.npm ci
2. npm run typecheck

Current behavior

node_modules/msw/lib/index.d.ts:4:63 - error TS2307: Cannot find module 'graphql' or its corresponding type declarations.

4 import { GraphQLError, OperationTypeNode, DocumentNode } from 'graphql';

Expected behavior

No errors when executing tsc.

@irico3 irico3 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 25, 2022
@kettanaito
Copy link
Member

Hey, @takanokana. Thanks for reporting this.

This issue is tied to the recent discussion around graphql here: #1356. You can find more info about it in the linked pull request.

We're looking for contributors to fix this. Would you like to help us out?

@mattcosta7
Copy link
Contributor

mattcosta7 commented Aug 25, 2022

Hey, @takanokana. Thanks for reporting this.

This issue is tied to the recent discussion around graphql here: #1356. You can find more info about it in the linked pull request.

We're looking for contributors to fix this. Would you like to help us out?

As a first step, I wonder if a patch release removing the optional peerDependency Meta might be a stopgap (npm should, i believe, install peers automatically - but not 100% sure offhand). From there, most users shouldn't be warned / see errors.

After that - Separating out the graphql entry might be possible, but not super clear yet

@nathanredblur
Copy link

nathanredblur commented Aug 26, 2022

I'm getting this using the latest version ("msw": "^0.45.0") and I can not compile. I just want to mock my regular API.

Module not found: Error: Can't resolve 'graphql' in '/.../node_modules/msw/lib'

any workaround?

@mattcosta7
Copy link
Contributor

I'm getting this using the latest version ("msw": "^0.45.0") and I can not compile. I just want to mock my regular API.

Module not found: Error: Can't resolve 'graphql' in '/.../node_modules/msw/lib'

any workaround?

npm i graphql or downgrade to 0.44.x

mattcosta7 added a commit to mattcosta7/msw that referenced this issue Aug 30, 2022
this makes the graphql peer dependency required. While the hope is to eventually avoid the need to
require the graphql library for users who don't declare graphql requests directly, the current
architecture means that many tools fails to properly compile without error/warning without this.

Since NPM 7, npm will automatically install peer dependencies, which should avoid consumers of msw
having to manually install graphql.

re mswjs#1371
mattcosta7 added a commit to mattcosta7/msw that referenced this issue Aug 30, 2022
removes the previous attempt at making graphql optional by lazily requiring it instead of importing
it.  This didn't have the intended affect of helping to avoid parsing in many environments, and
might be confusing and/or cause friction with a future migration to using native modules and
providing an export that can be treeshaken in all environments.

re mswjs#1371
@kettanaito
Copy link
Member

We're opening a fix in #1381. Everyone is welcome to participate in the discussion there.

kettanaito pushed a commit that referenced this issue Sep 1, 2022
* fix(package.json): make graphql non-optional peerDependency

this makes the graphql peer dependency required. While the hope is to eventually avoid the need to
require the graphql library for users who don't declare graphql requests directly, the current
architecture means that many tools fails to properly compile without error/warning without this.

Since NPM 7, npm will automatically install peer dependencies, which should avoid consumers of msw
having to manually install graphql.

re #1371

* refactor: graphql imported by import instead of require

removes the previous attempt at making graphql optional by lazily requiring it instead of importing
it.  This didn't have the intended affect of helping to avoid parsing in many environments, and
might be confusing and/or cause friction with a future migration to using native modules and
providing an export that can be treeshaken in all environments.

re #1371

* fix: use type import for graphql types

* fix: make graphql a dependency instead of peer
@kettanaito
Copy link
Member

Released: v0.46.1 🎉

This has been released in v0.46.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.

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

Successfully merging a pull request may close this issue.

4 participants