首页前端技术js代码运行报错Warning:To load an ES module, set "type":"module"in the package.json or use the .mjs

js代码运行报错Warning:To load an ES module, set "type":"module"in the package.json or use the .mjs

woniu 05-27 06:12 134次浏览 0条评论

报错信息

vscode运行js代码报错:(node:20452) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension. 

js代码运行报错Warning:To load an ES module, set "type":"module"in the package.json or use the .mjs  第1张

# 查看报错信息
Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
警告:加载ES模块时,在package.json包中设置“ type”:“ module”或使用.mjs扩展名。

解决方案

1、安装新版node.js

2、使用npm init -y初始化项目,生成一个pakeage.json文件

3、在pakeage.json文件中添加"type": "module"

同类型报错的情况,都可以使用该方案解决!

js代码运行报错Warning:To load an ES module, set "type":"module"in the package.json or use the .mjs  第2张

执行结果

js代码运行报错Warning:To load an ES module, set "type":"module"in the package.json or use the .mjs  第3张

总结

js代码运行报错Warning:To load an ES module set "type":"module"in the package.json or use the .mjs
深入探索数据库MySQL性能优化与复杂查询相关操作 ES6中export default和export之间的区别详解
相关内容
发表评论

游客 回复需填写必要信息