背景
使用 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
}
},