NuroDev / lemonsqueezy.ts

🍋 JavaScript / TypeScript SDK for the Lemon Squeezy API
https://paka.dev/npm/lemonsqueezy.ts
MIT License
159 stars 16 forks source link

TypeError: First parameter has member 'readable' that is not a ReadableStream. #2

Open madebyfabian opened 1 year ago

madebyfabian commented 1 year ago

First of all, thanks for your work on this module. It's great to not having to wrap the API manually in my project. I'ved noticed that it works great, returns data, but throws this error when it's being used inside a Nuxt 3 Server:

[nitro] [dev] [unhandledRejection] TypeError: First parameter has member 'readable' that is not a ReadableStream.                                                                                      10:37:19
    at assertReadableStream (file:///Users/fabian/Desktop/code/nuxt-project/node_modules/.pnpm/node-fetch-native@1.0.1/node_modules/node-fetch-native/dist/shared/node-fetch-native.25a180d0.mjs:428:21)
    at convertReadableWritablePair (file:///Users/fabian/Desktop/code/nuxt-project/node_modules/.pnpm/node-fetch-native@1.0.1/node_modules/node-fetch-native/dist/shared/node-fetch-native.25a180d0.mjs:3505:11)
    at ReadableStream.pipeThrough (file:///Users/fabian/Desktop/code/nuxt-project/node_modules/.pnpm/node-fetch-native@1.0.1/node_modules/node-fetch-native/dist/shared/node-fetch-native.25a180d0.mjs:3580:33)
    at fetchFinale (/Users/fabian/Desktop/code/nuxt-project/node_modules/.pnpm/undici@5.20.0/node_modules/undici/lib/fetch/index.js:973:52)
    at mainFetch (/Users/fabian/Desktop/code/nuxt-project/node_modules/.pnpm/undici@5.20.0/node_modules/undici/lib/fetch/index.js:773:5)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Reproduction: https://stackblitz.com/edit/github-dpsgxe

Do you have any idea what this could cause? If you think this is specific to Nuxt, I'll create an issue there.

NuroDev commented 1 year ago

Checking the stack trace this seems like more an issue with undici & subsequently node-fetch-native. Having a quick look through the undici repo issues there's nothing mentioning First parameter has member 'readable' that is not a ReadableStream so I'm not too sure right now.

I will take a deeper look into this issue at a later date.

Parth971 commented 1 year ago

First of all, thanks for your work on this module. It's great to not having to wrap the API manually in my project. I'ved noticed that it works great, returns data, but throws this error when it's being used inside a Nuxt 3 Server:

[nitro] [dev] [unhandledRejection] TypeError: First parameter has member 'readable' that is not a ReadableStream.                                                                                      10:37:19
    at assertReadableStream (file:///Users/fabian/Desktop/code/nuxt-project/node_modules/.pnpm/node-fetch-native@1.0.1/node_modules/node-fetch-native/dist/shared/node-fetch-native.25a180d0.mjs:428:21)
    at convertReadableWritablePair (file:///Users/fabian/Desktop/code/nuxt-project/node_modules/.pnpm/node-fetch-native@1.0.1/node_modules/node-fetch-native/dist/shared/node-fetch-native.25a180d0.mjs:3505:11)
    at ReadableStream.pipeThrough (file:///Users/fabian/Desktop/code/nuxt-project/node_modules/.pnpm/node-fetch-native@1.0.1/node_modules/node-fetch-native/dist/shared/node-fetch-native.25a180d0.mjs:3580:33)
    at fetchFinale (/Users/fabian/Desktop/code/nuxt-project/node_modules/.pnpm/undici@5.20.0/node_modules/undici/lib/fetch/index.js:973:52)
    at mainFetch (/Users/fabian/Desktop/code/nuxt-project/node_modules/.pnpm/undici@5.20.0/node_modules/undici/lib/fetch/index.js:773:5)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Reproduction: https://stackblitz.com/edit/github-dpsgxe

Do you have any idea what this could cause? If you think this is specific to Nuxt, I'll create an issue there.

Nice job, you API key is now public and its working image

madebyfabian commented 1 year ago

@Parth971 That's why I wrote "Never do that in your code!" lol. It's just a test project.

cloudatlas9 commented 11 months ago

Suddenly running into this issue now as well. Didn't change code around creating the checkout URL.

Any update or more insights in the meantime?

EDIT: Found the issue, which seems to have been a peer dependency conflict. It started happening after I installed the openai npm module. This was the error I got:

>  TypeError: First parameter has member 'readable' that is not a ReadableStream.
>      at assertReadableStream (/dev/functions/node_modules/web-streams-polyfill/dist/polyfill.js:362:19)
>      at convertReadableWritablePair (/dev/functions/node_modules/web-streams-polyfill/dist/polyfill.js:3524:9)
>      at ReadableStream.pipeThrough (/dev/functions/node_modules/web-streams-polyfill/dist/polyfill.js:3608:29)
>      at fetchFinale (/dev/functions/node_modules/undici/lib/fetch/index.js:973:52)
>      at mainFetch (/dev/functions/node_modules/undici/lib/fetch/index.js:773:5)
>      at processTicksAndRejections (node:internal/process/task_queues:96:5)

When I commented out the import of the openai module, the error did not occur. The openai module has web-streams-polyfill as a dependency:

"openai": {
      "version": "4.12.3",
      "resolved": "https://registry.npmjs.org/openai/-/openai-4.12.3.tgz",
      "integrity": "sha512-Kw8M8qioKg+iw2tCpdJ1G772uV0tk4SRF1MtySYSPr82YH+Csl61kYv2KzKAOqINcOVn5eSN26t0ImIsdJexfw==",
      "requires": {
        "@types/node": "^18.11.18",
        "@types/node-fetch": "^2.6.4",
        "abort-controller": "^3.0.0",
        "agentkeepalive": "^4.2.1",
        "digest-fetch": "^1.3.0",
        "form-data-encoder": "1.7.2",
        "formdata-node": "^4.3.2",
        "node-fetch": "^2.6.7",
        "web-streams-polyfill": "^3.2.1"
      },
      "dependencies": {
     //...
      }
    },

Lemonsqueezy.ts only has undici as a dependency:

"node_modules/lemonsqueezy.ts": {
      "version": "0.1.7",
      "resolved": "https://registry.npmjs.org/lemonsqueezy.ts/-/lemonsqueezy.ts-0.1.7.tgz",
      "integrity": "sha512-7COfsFaPVsz4ik6+b5hVI/PMyu6FE+PmrbNvk1G89P826XVRRnidVhDAes+Ed42RLyigc8bBHFbuUZSglPTO0g==",
      "dependencies": {
        "undici": "^5.20.0"
      },
      "engines": {
        "node": ">=16.*"
      }
    },

It seems that undici is using web-streams-polyfill under the hood, from the error stack trace..

What fixed the error in my case was the order of importing. When I changed it so openai is imported after lemonsqueey.ts, the error did not occur anymore.