js代码运行报错Warning:To load an ES module, set "type":"module"in the package.json or use the .mjs
报错信息
vscode运行js代码报错:(node:20452) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
# 查看报错信息
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的文章就介绍到这了,更多相关js代码运行Warning To load an ES module内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
js Firefox 加入收藏夹功能代码 兼容Firefox 和 IE
最近改用Firefox后,发现很多网站的“加入收藏”链接点击无效了,后来发现原来是IE浏览器和Firefox浏览器的“加入收藏夹”的写法是不同的。2009-12-12
最新评论