graphql-request: Module not found: Can't resolve 'encoding' in 'path/node_modules/node-fetch/lib'
Hi Im using graphql-request with next 13.1 however it throw this warning which is related to this package:
Module not found: Can't resolve 'encoding' in 'path/node_modules/node-fetch/lib'
Import trace for requested module:
./node_modules/node-fetch/lib/index.js
./node_modules/cross-fetch/dist/node-ponyfill.js
./node_modules/graphql-request/dist/index.js
./src/lib/gql/getClient.ts
./src/app/panel/page.tsx
I’m using node v18.
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 11
- Comments: 18 (4 by maintainers)
I ran into this too.
It’s an optional dependency that’s loaded by
node-fetch:https://github.com/node-fetch/node-fetch/blob/2.x/src/body.js#L13-L14
However, this has been removed in v3 of the same library. It looks like
cross-fetchneeds to update the dependency:https://github.com/lquixada/cross-fetch/blob/main/package.json#L69
There is a PR open for this: https://github.com/lquixada/cross-fetch/pull/144
But there has been no activity in the last 9 months on the repo. I’m not holding my breath.
Perhaps a different library handles this better?
I fixed this issue by installing the
encodingdependency next to thegraphql-requestin my package.json. (I’m usingpnpm)I would imagine that most client side users are going to be getting the native fetch at this point?
In a year or two I would be inclined to dropping polyfillijg entirely from this library and defaulting to leveraging node and client shared base of wg fetch spec. Maybe when node 16 is end of life.
Im not familiar with this corner of the ecosystem. Am I thinking about this wrong your in opinion?
@jasonkuhrt looks like that library is not maintained anymore.
I have the same issue with graphql-request with next 13.1. Any temporary solutions?