ped*_*uis 45 javascript parsing sublimetext eslint
我有一个eslint的问题,它给了我[解析错误关键字导入是保留]这只发生在sublime,在原子编辑器工作得很好.我有意见
.eslintrc.js
module.exports = {
"extends": "airbnb",
"plugins": [
"react"
]
};
Run Code Online (Sandbox Code Playgroud)
的package.json
{
"name": "paint",
"version": "0.0.0",
"description": "paint on the browser",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"paint",
"javascript"
],
"author": "",
"license": "ISC",
"devDependencies": {
"browserify": "^11.2.0",
"eslint": "^2.2.0",
"eslint-config-airbnb": "^2.1.1",
"eslint-plugin-react": "^3.11.2",
"gulp-babel": "^5.2.1",
"gulp-clean": "^0.3.1",
"gulp-stylus": "^2.2.0",
"vinyl-source-stream": "^1.1.0"
}
}
Run Code Online (Sandbox Code Playgroud)
Ima*_*adi 105
将其添加到.eslintrc的根目录中
"parser": "babel-eslint"
Run Code Online (Sandbox Code Playgroud)
小智 29
解决"关键字导入已保留"错误的eslint选项是parserOptions.sourceType
.将其设置为"module"
允许使用import
关键字.
.eslintrc
{
"parserOptions": {
"sourceType": "module"
}
}
Run Code Online (Sandbox Code Playgroud)
文档: https ://eslint.org/docs/user-guide/configuring#specifying-parser-options
Man*_*ddy 16
花了 30 分钟 - 尝试了所有解决方案,但效果不佳,所以分享这个。
即使在此时 - 2020 年 4 月,也可以在new react app
和 中看到该问题Visual Code
。
.eslintrc.js
在根文件夹中创建一个文件(在package.json
,或在/src/
目录旁边).eslintrc.js
.eslintrc.js
文件内容:
module.exports = {
env: {
commonjs: true,
node: true,
browser: true,
es6: true,
jest: true,
},
extends: ["eslint:recommended", "plugin:react/recommended"],
globals: {},
parser: "babel-eslint",
parserOptions: {
ecmaFeatures: {
jsx: true,
},
ecmaVersion: 2018,
sourceType: "module",
},
plugins: ["react", "import", "react-hooks"],
ignorePatterns: ["node_modules/"],
rules: {},
settings: {
react: {
version: "latest", // "detect" automatically picks the version you have installed.
},
},
};
Run Code Online (Sandbox Code Playgroud)
希望有帮助。
小智 9
不确定,但尝试将文件重命名为.eslintrc并使用
{
"extends": "airbnb",
"plugins": ["react"]
};
Run Code Online (Sandbox Code Playgroud)
还要确保您已安装所需的软件包。 github.com/airbnb/javascript
当前得票最高的答案有效。但是,它不再处于维护状态,新建议的方法是使用 mono 存储库中的版本。
安装
$ npm install eslint @babel/core @babel/eslint-parser --save-dev
# or
$ yarn add eslint @babel/core @babel/eslint-parser -D
Run Code Online (Sandbox Code Playgroud)
.eslintrc.js
module.exports = {
parser: "@babel/eslint-parser",
};
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
40084 次 |
最近记录: |