agisboye / app-store-server-api

A Node.js client for the App Store Server API
MIT License
218 stars 36 forks source link

No matching export in "node-modules-polyfills:crypto" for import "X509Certificate" #35

Closed Desttro closed 1 year ago

Desttro commented 1 year ago

I use a library with Cloudflare Workers:

"devDependencies": {
  "@cloudflare/workers-types": "^4.20230904.0",
  "typescript": "^5.2.2",
  "wrangler": "^3.7.0"
}

when I run the application through the wrangler, it returns an error:

✘ [ERROR] No matching export in "node-modules-polyfills:crypto" for import "X509Certificate"
 ../../node_modules/app-store-server-api/dist/esm/Decoding.js:37:9:
   37 │ import { X509Certificate } from "crypto";
      ╵          ~~~~~~~~~~~~~~~
✘ [ERROR] Failed to build

When I make the following changes, everything works as it should:

// src/Decoding.ts | 4 ++--

-import { X509Certificate } from "crypto"
+import * as crypto from "crypto"

-  const x509certs = certificates.map(c => new X509Certificate(c))
+  const x509certs = certificates.map(c => new crypto.X509Certificate(c))
agisboye commented 1 year ago

The Cloudflare Workers doesn't support the Node Crypto API (which is what this library uses). Instead it relies on the Web Crypto API.

I'm surprised that you found your example to work since I can't find any reference stating that Web Crypto contains the X509Certificate class (or any other way of working with X509 certificates for that matter).

Desttro commented 1 year ago

So after further testing, I came across a bug - the solution is not functional. Everything starts and pretends to work. But when a function like decodeTransaction is to be executed it throws an error.

Are you planning to add support for Web Crypto API?

I will try to find a solution - I will share it.

agisboye commented 1 year ago

That makes sense. It throws an error because crypto.X509Certificate is undefined. 😊

I don't have any plans of adding support for Web Crypto. I'd prefer not to add any dependencies that are unnecessary for the majority of users of this library (those running Node.js). If you can come up with a solution I'm happy to take a look.

Desttro commented 1 year ago

Fixed in fork

saviourdog commented 1 year ago

hi, @agisboye ,First of all, thank you for providing such a great plugin. However, there are increasingly more JavaScript runtime environments available today, such as Deno, Bun, and Cloudflare Workers, they may not necessarily support all the APIs of Node.js. Therefore, I would still appreciate it if you could support these platforms if you have the time. Thank you.

agisboye commented 1 year ago

Hi @saviourdog,

Thanks for using the library! I unfortunately don't have the time to add support for every new runtime that pops up. If you want to propose a solution for supporting other runtimes, I'd be happy to have a discussion around it.