首页 > 其他分享 >Cannot use import statement outside a module

Cannot use import statement outside a module

时间:2023-03-20 14:01:28浏览次数:31  
标签:use code outside module js json www test

参考资料:https://www.jianshu.com/p/60a8a74f5eee?ivk_sa=1024320u

 使用 vs code 调试js 代码,出现如上报错

解决过程:

  1. npm init -y
  2. 在 package.json 中添加字段 type
package.json
{
"name": "promise",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

标签:use,code,outside,module,js,json,www,test
From: https://blog.51cto.com/u_12890843/6132734

相关文章