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