1). 4:1 error Parsing error: The keyword 'import' is reserved
确保.eslintrc文件存在,并且内容为
{
"extends": "airbnb",
"plugins": ["react"]
}
2). Value "data["0"].VariableDeclarator" has additional properties.
如下所示错误代码,是因为最新的eslint需要重新配置,按照下面路径方法配置即可:eslint-config-airbnb-base安装配置
ERROR in ./src/index.js
Module build failed: Error: /home/suwu150/WebStormProject/electron-desktop-tools/node_modules/eslint-config-airbnb-base/rules/es6.js:
Configuration for rule "prefer-destructuring" is invalid:
Value "data["0"].VariableDeclarator" has additional properties.
Value "data["0"].AssignmentExpression" has additional properties.
Referenced from: /home/suwu150/WebStormProject/electron-desktop-tools/node_modules/eslint-config-airbnb-base/index.js
Referenced from: airbnb
Referenced from: /home/suwu150/WebStormProject/electron-desktop-tools/.eslintrc
at validateRuleOptions (/home/suwu150/WebStormProject/electron-desktop-tools/node_modules/eslint/lib/config/config-validator.js:109:15)
3). - Unexpected top-level property "comma-dangle".
ERROR in ./src/index.js
Module build failed: Error: ESLint configuration in /home/suwu150/WebStormProject/electron-desktop-tools/.eslintrc is invalid:
- Unexpected top-level property "comma-dangle".
at validateConfigSchema (/home/suwu150/WebStormProject/electron-desktop-tools/node_modules/eslint/lib/config/config-validator.js:214:15)
at Object.validate (/home/suwu150/WebStormProject/electron-desktop-tools/node_modules/eslint/lib/config/config-validator.js:231:5)
Unexpected top-level property,我的原因是没有将规则写对地方,
错误的写法如下所示:
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
}
},
"rules": {
"semi": 2
},
"comma-dangle": [1,"always-multiline"],
"plugins": ["react"],
"extends": "airbnb"
}
正确的写法如下所示:
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true,
"experimentalObjectRestSpread": true
}
},
"rules": {
"semi": 2,
"comma-dangle": ["off"]
},
"plugins": ["react"],
"extends": "airbnb"
}
4). Parsing error: Unexpected token :
或者 Parsing error: Unexpected token =
34:52 error Parsing error: Unexpected token :
✖ 1 problem (1 error, 0 warnings)
@ ./src/store/configureStore.js 6:19-58
@ ./src/index.js
@ multi webpack-hot-middleware/client?path=http://localhost:3000/__webpack_hmr babel-polyfill ./src/index.js
Use the babel-eslint
parser in your ESLint configuration.
也就是在.eslintrc中添加"parser": "babel-eslint",
即可
安装依赖包:npm install babel-eslint –save
{
"parser": "babel-eslint",
"plugins": ["react"],
...
}
5).error: Expected linebreaks to be ‘LF’ but found ‘CRLF’
我们从github上拉别人项目的时候。有时候会遇到这个报错:
error: Expected linebreaks to be ‘LF’ but found ‘CRLF’
这就是eslint的报错了,可能是原作者用的是linux系统。
只需在eslintrc文件里面将
linebreak-style: [“error”, “unix”]
改成
linebreak-style: [“error”, “windows”](我用的是windows)即可