relay-tools / relay-hooks

Use Relay as React hooks
https://relay-tools.github.io/relay-hooks/docs/relay-hooks.html
MIT License
540 stars 56 forks source link

feat: esm support #161

Closed n1ru4l closed 3 years ago

n1ru4l commented 3 years ago

I noticed that the esm version was broken due to @restart/hooks not being esm compatible and the es module export entry in the package.json missing.

I removed the @restart/hooks dependency in favor of a simply inline of the logic and also adjusted the package.json for the es export.

With those changes, relay-hooks can be successfully used with snowpack.

morrys commented 3 years ago

Hi @n1ru4l, thanks for your PR, I didn't add the module in the package because I was waiting for help to verify ESM support 💯

In this PR https://github.com/relay-tools/relay-hooks/pull/162 I have added the tests for useMutation so that I can better verify this PR :)

n1ru4l commented 3 years ago

After digging more, for Node.js to be compatible the file extension of the modules must be .mjs and all the imports must specify the .mjs extension. See https://github.com/enisdenjo/graphql-ws/pull/110/files

Since React does not ship ESM modules Node.js support does not matter that much, however, this library will hopefully not require any more changes when react starts shipping esm modules :)

morrys commented 3 years ago

hi @n1ru4l, can you update the PR with the master and fix the warnings?

n1ru4l commented 3 years ago

@morrys done :)

morrys commented 3 years ago

@n1ru4l I tried the bundle in the example projects cra and pagination-nextjs-ssr and I get errors similar to this: https://github.com/facebook/create-react-app/issues/10356

n1ru4l commented 3 years ago

@morrys Seems like create-react-app is not properly configured to support the .mjs extension.

An alternative approach (that could potentially break the common js module) could be the following: https://unpkg.com/browse/@tinyhttp/app@1.1.12/package.json

"type": "module",

This tells Node.js that any .js file should be treated as if it is was a .mjs file.

n1ru4l commented 3 years ago

I found this and will try it: https://github.com/d3/d3/issues/3469#issue-809713670

alex-gopuff commented 3 years ago

When will this be merged?

morrys commented 3 years ago

For now it is not merged because there are problems https://github.com/relay-tools/relay-hooks/pull/161#issuecomment-779247359

n1ru4l commented 3 years ago

i now have a solution that works consistently. I will try to update the PR this week :)