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

feat: restore main field of package.json for environments that do not support exports field #526

Merged
merged 2 commits into from May 18, 2023

Conversation

morishin
Copy link
Contributor

@morishin morishin commented May 13, 2023

I tried to use graphql-request for a ReactNative app. But build errors occured because metro bundler unfortunately does not support exports field yet...
So I would like to restore main field which was dropped by facebook/metro#670.
This change would only restore backward compatibility and would not have any bad effect on modern environments.

Copy link
Owner

@jasonkuhrt jasonkuhrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please update the docs about this topic. Just remove them. Also please make a new issue to remove main once the Metro issue is closed. Thanks!

@morishin
Copy link
Contributor Author

I missed the workaround in the README! (sorry 💦 )
I tried the workaround, however, the following errors are still appearing.

So I would like this PR to be merged for fixing the errors. I will update the docs and make the new issue.

Metro has encountered an error: While trying to resolve module `graphql-request` from file `/app/lib/graphql/useGraphQL.ts`, the package `/app/node_modules/graphql-request/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/app/node_modules/graphql-request/index`. Indeed, none of these files exist:

  * /app/node_modules/graphql-request/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
  * /app/node_modules/graphql-request/index/index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json): /app/node_modules/metro/src/node-haste/DependencyGraph.js (283:17)

  281 |         }
  282 |         if (error instanceof InvalidPackageError) {
> 283 |           throw new PackageResolutionError({
      |                 ^
  284 |             packageError: error,
  285 |             originModulePath: from,
  286 |             targetModuleName: to,

ABI48_0_0RCTFatal
__37-[ABI48_0_0RCTCxxBridge handleError:]_block_invoke
_dispatch_call_block_and_release
_dispatch_client_callout
_dispatch_main_queue_drain
_dispatch_main_queue_callback_4CF
__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__
__CFRunLoopRun
CFRunLoopRunSpecific
GSEventRunModal
-[UIApplication _run]
UIApplicationMain
main
start_sim
0x0

@jasonkuhrt
Copy link
Owner

jasonkuhrt commented May 18, 2023

@morishin ok thanks

@jasonkuhrt jasonkuhrt changed the title Restore main field of package.json for environments that do not support exports field feat: restore main field of package.json for environments that do not support exports field May 18, 2023
@jasonkuhrt jasonkuhrt merged commit 71af6ab into jasonkuhrt:main May 18, 2023
@ismay
Copy link
Contributor

ismay commented May 18, 2023

Can you please update the docs about this topic. Just remove them. Also please make a new issue to remove main once the Metro issue is closed. Thanks!

Would it be possible to expand that to current tooling that is still using main? I'm still waiting on the resolve package to add support for parsing exports for example.

@jasonkuhrt
Copy link
Owner

@ismay yep please create that issue or chime into existing one if there, thanks!

@morishin morishin deleted the add-main-field-to-package-json branch May 23, 2023 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants