gpt4 book ai didi

nestjs - node-fetch@3 在 nestjs 中不支持,因为它是 ESM

转载 作者:行者123 更新时间:2023-12-05 08:13:05 26 4
gpt4 key购买 nike

我不能使用包“node-fetch@3”。我只是导入它,我的控制台将记录错误:

const node_fetch_1 = require("node-fetch");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/control-panel-nest2/node_modules/node-fetch/src/index.js from /home/control-panel-nest2/dist/bimwize/document.service.js not supported.
Instead change the require of index.js in /home/control-panel-nest2/dist/bimwize/document.service.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/home/control-panel-nest2/dist/bimwize/document.service.js:19:22)
at Object.<anonymous> (/home/control-panel-nest2/dist/bimwize/bimwize.module.js:14:28)
at Object.<anonymous> (/home/control-panel-nest2/dist/user/user.module.js:11:26)
at Object.<anonymous> (/home/control-panel-nest2/dist/app.module.js:17:23)
at Object.<anonymous> (/home/control-panel-nest2/dist/main.js:6:22)

我知道发生了什么。 node-fetch@3 只支持 esm 但不支持 commonjs 和 nestjs 将编译我所有的导入要求。

我不知道如何解决这个问题。我已经尝试使用 node-fetch@2,但是 node-fetch@2 缺少我想要的一些功能。

最佳答案

Nestjs 提供 HTTP 模块。这是文档网址: https://docs.nestjs.com/techniques/http-module

关于nestjs - node-fetch@3 在 nestjs 中不支持,因为它是 ESM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71566131/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com