gpt4 book ai didi

javascript - 要求 ('node-fetch' )给出 ERR_REQUIRE_ESM

转载 作者:行者123 更新时间:2023-12-04 11:38:11 36 4
gpt4 key购买 nike

我只是用

const fetch = require('node-fetch')
我得到
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Alex\Desktop\rollbot\node_modules\node-fetch\src\index.js from C:\Users\Alex\Desktop\rollbot\index.js not supported.
Instead change the require of C:\Users\Alex\Desktop\rollbot\node_modules\node-fetch\src\index.js in C:\Users\Alex\Desktop\rollbot\index.js to a
dynamic import() which is available in all CommonJS modules.
{
code: 'ERR_REQUIRE_ESM'
}
我所有的其他包都可以工作,只是 node-fetch 可以做到这一点。为了使用 node-fetch,我应该怎么做?

最佳答案

来自 node-fetch package readme :

node-fetch is an ESM-only module - you are not able to import it withrequire. We recommend you stay on v2 which is built with CommonJSunless you use ESM yourself. We will continue to publish critical bugfixes for it.


如果你想 require它,然后降级到 v2。
您拥有的另一个选项是使用异步 import('node-fetch').then(...)

关于javascript - 要求 ('node-fetch' )给出 ERR_REQUIRE_ESM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69087292/

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