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"
同類型報錯的情況,都可以使用該方案解決!
執(zhí)行結果
總結
到此這篇關于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內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
js正則表達式最長匹配(貪婪匹配)和最短匹配(懶惰匹配)用法分析
這篇文章主要介紹了js正則表達式最長匹配(貪婪匹配)和最短匹配(懶惰匹配)用法,結合實例形式分析了貪婪匹配與懶惰匹配的具體用法與相關注意事項,需要的朋友可以參考下2016-12-12JavaScript實現(xiàn)鼠標滑過圖片變換效果的方法
這篇文章主要介紹了JavaScript實現(xiàn)鼠標滑過圖片變換效果的方法,涉及javascript控制鼠標事件及樣式變換的技巧,非常具有實用價值,需要的朋友可以參考下2015-04-04cookie在javascript中的使用技巧以及隱私在服務器端的設置
cookie在javascript中的使用技巧,需要的朋友可以參考下2012-12-12