在nodejs代码中使用 import 替代require
kevin.Zhu 发布于:2023-10-24 23:31 分类:文摘 有 59 人浏览,获得评论 0 条
https://dev.to/amanhimself/how-to-use-es6-import-syntax-in-node-js-3df2
The solution to this error is in the first line of the above error snippet and is now a recommend way by Node.js. Set the "type": "module"
in package.json
file.
{ "type": "module" }
This solution works for the latest Node.js versions (which is 15.4.x
at the time of writing) and versions above 14.x.x
.