Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting errors while using 'got' package

I am using 'got' version '11.8.3' and I am getting below error.

/app/node_modules/got/dist/source/core/index.js:696 throw new TypeError('The payload has been already provided'); ^ TypeError: The payload has been already provided at Request.onLockedWrite (/app/node_modules/got/dist/source/core/index.js:696:19) at PassThrough. (node:internal/streams/pipeline:323:31)

Hence I tried to upgrade 'got' to latest (12.0.3). But after this I am getting below error:

/app/server/lib/my-api.js:8 const got_1 = __importDefault(require("got")); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/got/dist/source/index.js from /app/server/lib/my-api.js not supported. Instead change the require of index.js in /app/server/lib/my-api.js to a dynamic import() which is available in all CommonJS modules.

However, I am using this statement in my .ts file. import got from 'got'

Can you suggest on eliminating these errors

like image 319
Pavan Avatar asked Oct 25 '25 04:10

Pavan


1 Answers

here's a fix.

first

npm i fix-esm   

then you can import got package like this

const got = require("fix-esm").require("got");

Next install got version 10.0.0

npm i [email protected]  

Hope this helps. Cheers

like image 115
Lari Bright Avatar answered Oct 26 '25 18:10

Lari Bright



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!