REQUIRED('node-Fetch')提供ERR_REQUIRED_ESM [英] require('node-fetch') gives ERR_REQUIRE_ESM

查看:18
本文介绍了REQUIRED('node-Fetch')提供ERR_REQUIRED_ESM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只使用

const fetch = require('node-fetch')

我得到

Error [ERR_REQUIRE_ESM]: require() of ES Module C:UsersAlexDesktop
ollbot
ode_modules
ode-fetchsrcindex.js from C:UsersAlexDesktop
ollbotindex.js not supported.
Instead change the require of C:UsersAlexDesktop
ollbot
ode_modules
ode-fetchsrcindex.js in C:UsersAlexDesktop
ollbotindex.js to a 
dynamic import() which is available in all CommonJS modules.
{
  code: 'ERR_REQUIRE_ESM'
}

我的所有其他包都可以工作,只有节点获取可以做到这一点。要使用节点获取,我应该做些什么?

推荐答案

来自node-fetchpackage readme

节点获取是仅限ESM的模块-您不能使用导入它 需要。我们建议您继续使用v2,它是用CommonJS构建的 除非你自己使用ESM。我们将继续发布严重错误 已对其进行修复。

如果要require,请降级到v2。

另一个选项是使用异步import('node-fetch').then(...)

这篇关于REQUIRED('node-Fetch')提供ERR_REQUIRED_ESM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆