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
    }
  },

猜你喜欢

转载自www.cnblogs.com/notfound/p/12377684.html
今日推荐