我在node-fetch库中遇到了一个问题。新版本(3.0.3)的package.json中有package.json。这是一个问题,因为我将代码从ES6传输到使用require的常规js,然后得到...firebase_datasource.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.,我可以使用node-fetch的早期版本,它的package.json中的package.json中不包含"type": "module",但这不是一个解决方案。处理这个问题的正确方法是什么?
发布于 2021-11-12 21:19:05
node-fetch's README解释了该做什么:
CommonJS
来自node-fetch的v3是一个仅限ESM的模块--您不能用require()导入它。
如果无法切换到ESM,请使用与v2兼容的CommonJS。将继续为v2发布重要的bug修复程序。
npm安装节点-fetch@2
或者,您可以使用来自CommonJS的异步CommonJS函数异步加载node-fetch:
// mod.cjs const = (...args) =>导入(‘节点-提取’).then({default: fetch}) => fetch (...args);
https://stackoverflow.com/questions/69949022
复制相似问题