【问题标题】:Getting errors while using 'got' package使用 \'got\' 包时出错
【发布时间】:2022-09-25 19:33:14
【问题描述】:

我正在使用 \'got\' 版本 \'11.8.3\' 并且出现以下错误。

/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)

因此,我尝试将 \'got\' 升级到最新版本 (12.0.3)。但在此之后我得到以下错误:

/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.

但是,我在我的 .ts 文件中使用了这个语句。 import got from \'got\'

你能建议消除这些错误吗

  • 您的 TypeScript 设置正在将 import 转换为 require 并且 got 包与它不兼容
  • 在那种情况下,有什么办法可以消除得到\'11.8.3\'版本(\'有效载荷已经提供\')带来的第一个错误

标签: javascript node.js typescript npm dependencies


【解决方案1】:

这是一个修复。

第一的

npm i fix-esm   

然后你可以像这样导入包

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

下一次安装得到版本 10.0.0

npm i got@10.0.0  

希望这可以帮助。干杯

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多