[英]require() of ES modules not supported
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: D:\...\node_modules\normalize-url\index.js
[0] require() of ES modules is not supported.
[0] require() of D:\...\node_modules\normalize-url\index.js from D:\...\routes\api\users.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.
[0] Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from D:\Personnel\Linu
x downloads n docs\Docs\Project 2\node_modules\normalize-url\package.json.
I tried to downgrade the node-fetchand type:module, nothing worked.我试图降级 node-fetchand type:module,但没有任何效果。
You installed a new version of normalize-url whose package.json contains {type:module} this is deduced from:您安装了一个新版本的normalize-url ,其package.json包含{type:module}这是从:
...package.json contains "type":"module"
...package.json 包含“类型”:“模块”
Because modules are loaded using 'import' and not 'require', Node returns an error.因为模块是使用 'import' 而不是 'require' 加载的,所以 Node 会返回错误。
You probably need the CJS scripts.您可能需要 CJS 脚本。
Remove and reinstall the package the standard way ( npm remove normalize-url && npm i normalize-url
).以标准方式删除并重新安装 package(
npm remove normalize-url && npm i normalize-url
)。 If npm i normalize-url@latest
is installed then it is a ES2015 and only work with import statements.如果
npm i normalize-url@latest
已安装,则它是 ES2015 并且仅适用于导入语句。
Downgraded the node version to LTS, and it started working.将节点版本降级到 LTS,它开始工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.