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

Adapt Remix package to run on Cloudflare Workers #127

Closed
1 of 9 tasks
MedicusIO opened this issue Mar 20, 2022 · 26 comments
Closed
1 of 9 tasks

Adapt Remix package to run on Cloudflare Workers #127

MedicusIO opened this issue Mar 20, 2022 · 26 comments
Assignees

Comments

@MedicusIO
Copy link

Package

  • @clerk/clerk-js
  • @clerk/clerk-react
  • @clerk/nextjs
  • @clerk/remix
  • @clerk/clerk-expo
  • @clerk/backend-core
  • @clerk/clerk-sdk-node
  • @clerk/edge
  • other:

Description

The rootAuthLoader uses http2 which is a node package. Cloudflare Workers does not have access to Node.js packages, just plain javascript. Can this not be changed to fetch?

@nikosdouvlis nikosdouvlis self-assigned this Mar 23, 2022
@nikosdouvlis
Copy link
Member

Thanks for reporting that. A ticket for this issue already exists, so let me get back at you once the fix is deployed - will probably happen soon enough :)

@igneel64
Copy link
Contributor

Hey @MedicusIO :)
Can you please gives us some information on your setup and the packages used ? (an example repo would be even better)

@MedicusIO
Copy link
Author

After much soul searching I switched to Fly.IO which runs node (so this is less of an issue to me now). Cloudflare workers run V8 so anything that runs in the browser runs in a worker. The upside is there is no cold start like with lambda. However, you cannot use any node packages which is limiting.

@Slooowpoke
Copy link

Slooowpoke commented Apr 20, 2022

I've encountered this too I think, even just trying to run miniflare with Clerk doesn't seem to work.

I'm guessing it's because of Clerk only because of this error:

../../node_modules/http2-wrapper/source/index.js:2:22:
      2 │ const http2 = require('http2');
        ╵                       ~~~~~~~
  The package "http2" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

If I search through all the packages in the project for the ones that use http-wrapper, the only one I get is one called "got", which is used in Clerk-node. I'll try and put together a simple reproduction case but it might take until this weekend.

@igneel64
Copy link
Contributor

Thanks peeps, it would be really helpful for us to start checking the issue based on the setup and give you a resolution.

@Slooowpoke
Copy link

Slooowpoke commented Apr 21, 2022

Found five minutes this morning and it was actually easier than I thought to reproduce.
https://github.com/Slooowpoke/clerk-remix-workers

This is a fresh remix repo with Cloudflare workers set as the deployment target, I've added Clerk's root auth loader, nothing else. If you try to run this, it won't work. If you remove the two lines for Clerk from root.tsx it works. Hope that's helpful.

@SokratisVidros
Copy link
Contributor

SokratisVidros commented May 9, 2022

clerk-remix depends on clerk-node-sdk that uses got HTTP client. That is, the current version of clerk-remix works for Node runtimes. I will a PR later today using a cross fetch library.

@EArazli
Copy link

EArazli commented May 12, 2022

any update here?

@SokratisVidros
Copy link
Contributor

Still working on it. The latest status is that we need to find an isomorphic HTTP clients and an isomorphic crypto library. The HTTP client we picked for now is cross-fetch. Things are a bit trickier in the crypto world.

@EArazli
Copy link

EArazli commented May 13, 2022

Thanks for the update! Not sure if this helps, but CF workers implements the web crypto api and there seems to be something similar to cross-fetch for that use case. https://www.npmjs.com/package/isomorphic-webcrypto

There also seems to be support for the web crypto API in node directly but the earliest LTS with support seems to be 16
https://nodejs.org/api/webcrypto.html#web-crypto-api

SokratisVidros added a commit that referenced this issue May 31, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
@marcus-sa
Copy link

+1 this is also blocking me. Anything we can do to help speed up the process?

@marcus-sa
Copy link

Thanks for the update! Not sure if this helps, but CF workers implements the web crypto api and there seems to be something similar to cross-fetch for that use case. https://www.npmjs.com/package/isomorphic-webcrypto

There also seems to be support for the web crypto API in node directly but the earliest LTS with support seems to be 16 https://nodejs.org/api/webcrypto.html#web-crypto-api

According to MDN, it's supported from v15.

SokratisVidros added a commit that referenced this issue Jun 17, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
@SokratisVidros
Copy link
Contributor

SokratisVidros commented Jun 17, 2022

Folks, this is the first PR towards a more isomorphic architecture #290. It's still WIP as I am currently on paternity leave but the direction should be clear. Let us know what you think.

SokratisVidros added a commit that referenced this issue Jun 23, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
SokratisVidros added a commit that referenced this issue Jun 23, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
igneel64 pushed a commit that referenced this issue Jun 23, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
SokratisVidros added a commit that referenced this issue Jun 25, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
SokratisVidros added a commit that referenced this issue Jun 25, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
igneel64 pushed a commit that referenced this issue Jun 29, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
igneel64 pushed a commit that referenced this issue Jun 29, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
@marcus-sa
Copy link

@SokratisVidros any updates or any way to help speed up the process?

@marcus-sa
Copy link

Still working on it. The latest status is that we need to find an isomorphic HTTP clients and an isomorphic crypto library. The HTTP client we picked for now is cross-fetch. Things are a bit trickier in the crypto world.

There's https://github.com/sindresorhus/ky-universal by the same people who created got.

SokratisVidros added a commit that referenced this issue Jul 13, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
SokratisVidros added a commit that referenced this issue Jul 13, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
@SokratisVidros
Copy link
Contributor

Hey @marcus-sa, the PR introducing fetch will be merged later this week. The next step is to bump to Node 16 and use webcrypto. Apologies this is taking longer than expected but more pressuring tasks came up as we are in the process of releasing ClerkJS V4 with brand new components.

SokratisVidros added a commit that referenced this issue Jul 15, 2022
Polyfill global.fetch only in Node environments if necessary and increase interoperability for the SDK across Node and V8 runtime environments.

Fixes #127
@SokratisVidros
Copy link
Contributor

The first PR about fetch is now merged. Next week we will replace Node crypto with Web crypto.

@phpb-com
Copy link

Any update on this? Would be good to be finally able use Clerk with Remix and CF Pages. 🙏

@SokratisVidros
Copy link
Contributor

SokratisVidros commented Sep 7, 2022

Apologies for the delay. We are currently working to support Next.js 12.2 Middleware. Cloudflare workers for Remix and other frameworks are next on the list.

@phpb-com
Copy link

Is there any sort of timeline that we could refer to?

@SokratisVidros
Copy link
Contributor

We expect this to be resolved in November. As you can see in https://github.com/clerkinc/javascript/pull/460/files we've started rearchitecting our backend SDKS to make them work across web-interoperable runtimes.

@aerojeyenth
Copy link

@SokratisVidros May I know the status of this ? Is the support for Remix on Cloudflare workers is still experimental ?

@aerojeyenth
Copy link

@dimkl Thank you for tagging this to my comment but I am afraid and believe that these are not related. The document on your website clearly states that Edge runtime including Cloudflare Workers is supported
image
https://clerk.com/docs/quickstarts/get-started-with-remix

I am not sure if this ticket is still valid. Please kindly help this is a huge blocker for the work which I have planned. Thank you so much in advance.

@arjunyel
Copy link
Contributor

I am currently using Clerk plus Cloudflare Pages so I believe this can be closed

@SokratisVidros
Copy link
Contributor

Yes, Remix is fully supported across all runtimes.

@dimkl
Copy link
Contributor

dimkl commented Mar 21, 2023

@aerojeyenth your issue is not related to this. i will reopen the previous issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests