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

[Bug]: Not supported to run in Cloudflare Worker Edge environment #37

Open
wytxer opened this issue Jul 5, 2024 · 5 comments
Open

[Bug]: Not supported to run in Cloudflare Worker Edge environment #37

wytxer opened this issue Jul 5, 2024 · 5 comments
Assignees

Comments

@wytxer
Copy link

wytxer commented Jul 5, 2024

What happened?

Using the Next.js 14 + TypeScript tech stack, with the API set to the edge environment, an error occurs when calling paddle.transactions.create after importing the @paddle/paddle-node-sdk package: Module build failed: UnhandledSchemeError: Reading from "node:crypto".

Steps to reproduce

Reproduction code snippet:

// route.ts

import { Environment, Paddle } from '@paddle/paddle-node-sdk'

export const runtime = 'edge'

const paddle = new Paddle(process.env.PADDLE_SECRET_KEY!, {
  environment: Environment.production,
})

const transaction = await paddle.transactions.create({
  items: [
    {
      quantity: 1,
      priceId: 'priceId',
    },
  ],
})

What did you expect to happen?

I hope to use @paddle/paddle-node-sdk in an edge environment.

Logs

⨯ node:crypto
Module build failed: UnhandledSchemeError: Reading from "node:crypto" is not handled by plugins (Unhandled scheme).
Webpack supports "data:" and "file:" URIs by default.
You may need an additional plugin to handle "node:" URIs.
Import trace for requested module:
node:crypto
node_modules/@paddle/paddle-node-sdk/dist/esm/internal/api/client.js
node_modules/@paddle/paddle-node-sdk/dist/esm/paddle.js
node_modules/@paddle/paddle-node-sdk/dist/esm/index.js
@vijayasingam-paddle vijayasingam-paddle self-assigned this Jul 5, 2024
@vijayasingam-paddle
Copy link
Contributor

Hi @wytxer,
Thank you for opening this bug report with all the details.
I am sorry that you are running into this issue.

Our node SDK was built for Node.js Runtime, as Edge runtime uses web API some of the dependencies we use like the crypto module will not work.

Even though removing the node: prefix might solve the problem for you, I fear it will break for others. So that is not an option.

I will find a solution to this problem and get back to you once it is released.

Thank you.

@wytxer
Copy link
Author

wytxer commented Jul 6, 2024

Thank you for your reply. I am building a product based on Cloudflare Worker. Is there a plan for when it will be released? @vijayasingam-paddle

@vijayasingam-paddle
Copy link
Contributor

Hi @wytxer,
I am afraid that it will take a while for us to change this as we had not planned to run our SDK using web APIs and supporting both runtimes will be tricky.

We do support CloudFlare workers using NodeJS runtime. However, looking at your snippet, you are deploying a NextJS app to CloudFlare workers which as I understand can only run on an edge runtime.

If you don't mind me asking, is there any particular reason not to deploy this in Vercel or Netlify where the infra plays well with NextJS applications compared to CF workers?

Thank you.

@westlinkin
Copy link

@vijayasingam-paddle I'm trying to implement paddle in Cloudflare workers, As you mentioned,

We do support CloudFlare workers using NodeJS runtime.

I'm planning to use Cloudflare workers as the backend, so could you let me know if this works?

@vijayasingam-paddle
Copy link
Contributor

Hi @westlinkin,
Yes, our SDK works in CloudFlare workers using NodeJS runtime.
This issue is relevant only to the Edge runtime

Please feel free to reach out to us if you face any difficulties while integrating with your application.

Thank you.

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

No branches or pull requests

3 participants