Parsing error: ImportDeclaration should appear when the mode is ES6 and in the module context.


背景

使用 vs code 配置好ESlint,编写 js 代码时用到了 import 语句,在vs code的problem栏报错,内容如下 :

{
	"resource": "/c:/Users/john/WeChatProjects/small_fish_group_server/miniprogram/pages/goods-add/goods-add.js",
	"owner": "eslint",
	"severity": 8,
	"message": "Parsing error: ImportDeclaration should appear when the mode is ES6 and in the module context.",
	"source": "eslint",
	"startLineNumber": 1,
	"startColumn": 1,
	"endLineNumber": 1,
	"endColumn": 1
}

解决方法

  • 修改配置文件 .eslintrc.json,添加或修改以下内容

    其中,主要是 "sourceType" : "module" 这一行内容,其它内容作参考与定位

  "parserOptions": {
    "ecmaVersion": 6,
    "sourceType": "module",
    "ecmaFeatures": {
      "modules": true
    }
  },


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM