Cannot use import statement outside a module
参考资料:https://www.jianshu.com/p/60a8a74f5eee?ivk_sa=1024320u
使用 vs code 调试js 代码,出现如上报错
解决过程:
- npm init -y
- 在 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" }