【发布时间】:2021-12-02 04:00:28
【问题描述】:
我用谷歌搜索了一段时间,但找不到解决问题的解决方案。
我想使用“node-fetch”中的 fetch 函数,但是在我的代码中需要它时,我得到了错误:
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/xvma/stuff/Projekte/React/first-try/node_modules/node-fetch/src/index.js
require() of ES modules is not supported.
require() of /Users/xvma/stuff/Projekte/React/first-try/node_modules/node-fetch/src/index.js from /Users/xvma/stuff/Projekte/React/first-try/test.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.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/xvma/stuff/Projekte/React/first-try/node_modules/node-fetch/package.json.
In this file I want to use fetch()
我希望你们能帮助我,我尝试删除我的节点组件文件夹和包锁,但没有奏效。 另外,在我的 package.lock.json 中没有设置“type”="module"。
【问题讨论】:
-
请不要将您的错误和代码发布为图片!
-
你不需要 require "node-fetch" 来使用 fetch。
标签: node.js