Cannot use import statement outside a module

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

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

解决过程:

  1. npm init -y
  2. 在 package.json 中添加字段 type
  3. 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"
    }

     

posted on 2023-03-17 09:49  我和你并没有不同  阅读(126)  评论(0)    收藏  举报