在阅读了一些关于我的问题的问答后:
解析错误:“import”和“export”可能只出现在“sourceType:module”中
- 忽略 ESLint 错误:“import”和“export”可能只出现在顶层
- 在 ES6 中使用 import 和 require 的正确方法是什么?
- SyntaxError: 'import' 和 'export' 可能只出现在 'sourceType: module' 中 - 等等?
我将.eslintrc.json写到:
{
"extends": ["airbnb", "prettier", "plugin:node/recommended"],
"plugins": ["prettier"],
"env": {
"node": true,
"es6": true,
"browser": true
},
"parser": "babel-eslint",
"parserOptions": {
"ecmaVersion": 11,
"sourceType": "module",
"allowImportExportEverywhere": true
},
"rules": {
"prettier/prettier": "error",
"spaced-comment": "off",
"no-console": "warn",
"consistent-return": "off",
"func-names": "off",
"object-shorthand": "off",
"no-process-exit": "off",
"no-param-reassign": "off",
"no-return-await": "off",
"no-underscore-dangle": "off",
"class-methods-use-this": "off",
"prefer-destructuring": ["error", { "object": true, "array": false }],
"no-unused-vars": ["error", { "argsIgnorePattern": "req|res|next|val" }],
"semi": [2, "never"],
"object-curly-spacing": [2, "always"]
}
}
使用以下 devDependencies:
"devDependencies": {
"babel-eslint": "^10.0.3",
"eslint": "^6.4.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.3.0",
"eslint-plugin-import": "^2.18.2",
"eslint-plugin-jsx-a11y": "^6.2.3",
"eslint-plugin-node": "^10.0.0",
"eslint-plugin-prettier": "^3.1.1",
"eslint-plugin-react": "^7.14.3",
"eslint-plugin-react-hooks": "^1.7.0",
"nodemon": "^1.19.3",
"prettier": "^1.18.2"
},
并设置我的引擎:
"engines": {
"node": "^10"
}
当我用 Babel 编写测试模块时:
export default class Search {
constructor() {
alert('search test')
}
}
我收到以下警报:
尚不支持导入和导出声明。eslint(node/no-unsupported-features/es-syntax)
为什么我的设置不起作用?我可以modules/
在.eslintignore文件中写入忽略,但我想知道为什么我会收到此警报以及如何正确解决它?