Pavan
Pavan

Reputation: 31

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

Upvotes: 3

Views: 2914

Answers (1)

Lari Bright
Lari Bright

Reputation: 61

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

Upvotes: 4

Related Questions