Skip to content

Commit 71af6ab

Browse files
authored
feat: restore main field of package.json for environments that do not support exports field (#526)
1 parent ae1d8af commit 71af6ab

File tree

2 files changed

+1
-31
lines changed

2 files changed

+1
-31
lines changed

README.md

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -174,34 +174,3 @@ No. It is there for convenience so that you can get the tooling support like pre
174174
`graphql-request` is the most minimal and simplest to use GraphQL client. It's perfect for small scripts or simple apps.
175175

176176
Compared to GraphQL clients like Apollo or Relay, `graphql-request` doesn't have a built-in cache and has no integrations for frontend frameworks. The goal is to keep the package and API as minimal as possible.
177-
178-
#### Why is the package `main` field missing?
179-
180-
The `main` field was deprecated by Node.js on April 23 2019 when version 12 was released, in favour of [entrypoints (`exports` package manifest field)](https://nodejs.org/api/packages.html#package-entry-points). I believe enough time has passed that tools should be adopting the new standards now.
181-
182-
#### How do I work around React Native + Metro's lack of `exports` support?
183-
184-
You might encounter the error below when you try to build a React Native app that uses `graphql-request`:
185-
186-
```
187-
Error: While trying to resolve module "graphql-request" from file "/path/to/src/App.ts", the package "/path/to/node_modules/graphql-request/package.json" was successfully found. However, this package itself specifies a "main" module field that could not be resolved ("/path/to/node_modules/graphql-request/index".
188-
```
189-
190-
This happens because Metro [does not support yet](https://github.com/facebook/metro/issues/670) the `exports` field in package.json. A workaround for this problem is to edit the `metro.config.js` file in your project and add a new [`resolveRequest`](https://facebook.github.io/metro/docs/configuration/#resolverequest) for `graphql-request`. Like this:
191-
192-
```javascript
193-
resolver: {
194-
resolveRequest: (context, moduleName, platform) => {
195-
if (moduleName.startsWith('graphql-request')) {
196-
return {
197-
filePath: `${__dirname}/node_modules/graphql-request/build/esm/index.js`,
198-
type: 'sourceFile',
199-
}
200-
}
201-
202-
return context.resolveRequest(context, moduleName, platform)
203-
}
204-
}
205-
```
206-
207-
After doing this change, clear Metro's cache and restart your application.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"name": "graphql-request",
33
"version": "0.0.0-dripip",
44
"type": "module",
5+
"main": "./build/cjs/index.js",
56
"exports": {
67
".": {
78
"require": {

0 commit comments

Comments
 (0)