Version
4.0.3
Environment info
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-7300HQ CPU @ 2.50GHz
Binaries:
Node: 12.9.1 - C:Program Filesnodejsnode.EXE
npm: 6.10.2 - C:Program Filesnodejsnpm.CMD
npmPackages:
@vue/babel-helper-vue-jsx-merge-props: 1.0.0
@vue/babel-plugin-transform-vue-jsx: 1.0.0
@vue/babel-preset-app: 4.0.3
@vue/babel-preset-jsx: 1.1.1
@vue/babel-sugar-functional-vue: 1.0.0
@vue/babel-sugar-inject-h: 1.0.0
@vue/babel-sugar-v-model: 1.1.1
@vue/babel-sugar-v-on: 1.1.0
@vue/cli-overlay: 4.0.3
@vue/cli-plugin-babel: ^4.0.3 => 4.0.3
@vue/cli-plugin-eslint: ^4.0.3 => 4.0.3
@vue/cli-plugin-router: 4.0.3
@vue/cli-plugin-vuex: 4.0.3
@vue/cli-service: ^4.0.3 => 4.0.3
@vue/cli-shared-utils: 4.0.3
@vue/component-compiler-utils: 3.0.0
@vue/eslint-config-prettier: ^5.0.0 => 5.0.0
@vue/preload-webpack-plugin: 1.1.1
@vue/web-component-wrapper: 1.2.0
eslint-plugin-vue: ^5.2.3 => 5.2.3
vue: ^2.6.10 => 2.6.10
vue-clickaway: 2.2.2 => 2.2.2
vue-eslint-parser: undefined (5.0.0)
vue-hot-reload-api: 2.3.4
vue-loader: 15.7.1
vue-ls: ^3.2.1 => 3.2.1
vue-material: ^1.0.0-beta-11 => 1.0.0-beta-11
vue-router: ^3.1.3 => 3.1.3
vue-rx: ^6.2.0 => 6.2.0
vue-simple-spinner: ^1.2.8 => 1.2.8
vue-style-loader: 4.1.2
vue-template-compiler: 2.6.10 => 2.6.10
vue-template-es2015-compiler: 1.9.1
vue-the-mask: ^0.11.1 => 0.11.1
vue2-transitions: 0.3.0 => 0.3.0
npmGlobalPackages:
@vue/cli: 4.0.3
Steps to reproduce
I was working on a project created with @vue/cli@3.11.0
with @vue/cli-plugin-babel
and @vue/cli-plugin-eslint
also at 3.11.0
. Then I followed the migration with vue upgrade
and everything was updated without errors, until I try to run the project with npm run serve
.
What is expected?
Project running without errors.
What is actually happening?
A lot of repeated errors for each .vue
file, like that:
error in ./src/pages/User/Read.vue
Module Error (from ./node_modules/eslint-loader/index.js):
error: Parsing error: Cannot find module 'babel-eslint'
Require stack:
- D:sample-projectnode_moduleseslint-plugin-vuenode_modulesvue-eslint-parserindex.js
- D:sample-projectnode_moduleseslint-plugin-vuelibutilsindex.js
- D:sample-projectnode_moduleseslint-plugin-vuelibrulesarray-bracket-spacing.js
- D:sample-projectnode_moduleseslint-plugin-vuelibindex.js
- D:sample-projectnode_moduleseslintnode_modulesimport-freshindex.js
- D:sample-projectnode_moduleseslintlibconfigconfig-file.js
- D:sample-projectnode_moduleseslintlibconfig.js
- D:sample-projectnode_moduleseslintlibcli-engine.js
- D:sample-projectnode_moduleseslintlibapi.js
- D:sample-projectnode_moduleseslint-loaderindex.js
- D:sample-projectnode_modulesloader-runnerlibloadLoader.js
- D:sample-projectnode_modulesloader-runnerlibLoaderRunner.js
- D:sample-projectnode_moduleswebpacklibNormalModule.js
- D:sample-projectnode_moduleswebpacklibNormalModuleFactory.js
- D:sample-projectnode_moduleswebpacklibCompiler.js
- D:sample-projectnode_moduleswebpacklibwebpack.js
- D:sample-projectnode_modules@vuecli-servicelibcommandsserve.js
- D:sample-projectnode_modules@vuecli-servicelibService.js
- D:sample-projectnode_modules@vuecli-servicebinvue-cli-service.js
The error persists with or without babel-eslint
in package.json
as a dev dependency.
#reactjs #next.js #babeljs #eslint
#reactjs #next.js #babeljs #eslint
Вопрос:
Пытаюсь установить eslint в yarn create next-app
, но получаю следующую ошибку при запуске linter:
Ошибка: не удалось загрузить анализатор ‘@babel/ eslint-parser’, объявленный в ‘.eslintrc.js ‘: Не удается найти модуль ‘@babel/core/package.json’
Подробно:
info - Loaded env from /project/.env
Error: Failed to load parser '@babel/eslint-parser' declared in '.eslintrc.js': Cannot find module '@babel/core/package.json'
Require stack:
- /project/node_modules/@babel/eslint-parser/lib/parse.cjs
- /project/node_modules/@babel/eslint-parser/lib/index.cjs
- /project/node_modules/@eslint/eslintrc/dist/eslintrc.cjs
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Вот мой .eslintrc.js
конфигурационный файл:
browser: true,
es2020: true,
es6: true,
node: true
},
extends: ['airbnb', 'prettier', 'next/core-web-vitals'],
parser: '@babel/eslint-parser',
parserOptions: {
ecmaVersion: 2021,
requireConfigFile: false
},
plugins: ['react']
И package.json
подать
"devDependencies": {
"@babel/eslint-parser": "^7.16.3",
"eslint": "^8.4.1",
"eslint-config-airbnb": "^19.0.2",
"eslint-config-next": "^12.0.7",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-react": "^7.27.1",
"prettier": "^2.5.1"
}
Ответ №1:
У меня была эта проблема раньше. Позвольте мне помочь вам с несколькими вещами, которые вы можете попробовать.
Первый вариант:
npm remove babel-eslint amp;amp; npm install --save-dev @babel/core @babel/eslint-parser
Второй вариант:
при .eslintrc
изменении вашего файла просто удалите ваш анализатор:
"parser": "@babel/eslint-parser " // delete this line
Третий вариант:
измените свой анализатор вашего пакета модулей узла:
"parser": "/usr/local/lib/node_modules/babel-eslint",
Комментарии:
1. Спасибо, но ваш ответ не сработал.
2. Это не работает … братан
Ответ №2:
установить также babel / core:
$ npm install eslint @babel/core @babel/eslint-parser --save-dev
# or
$ yarn add eslint @babel/core @babel/eslint-parser -D
As of March 2020, babel-eslint
has been deprecated, and is now @babel/eslint-parser
. That doesn’t stop it (as of March 2021) being downloaded 6.5 million times per week. You wouldn’t know this unless you attempted to add it as a new dependency, in which case npm
would tell you:
npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
Upgrading is straightforward but I couldn’t find any clear guides — so if you want to avoid the trial and error you can follow the below steps (which I’ve tested on Create React App, Next.js, and Vite apps — which all use Babel under the hood).
As to why babel-eslint
has been deprecated? It’s documented in the (now archived) babel-eslint repo:
As of the v11.x.x release, babel-eslint now requires Babel as a peer dependency and expects a valid Babel configuration file to exist. This ensures that the same Babel configuration is used during both linting and compilation.
Short version
- Remove
babel-eslint
- Add
@babel/eslint-parser
@babel/preset-react
- You may also need the peer dependency
@babel/core
(npm7 installs peer dependencies by default)
- You may also need the peer dependency
- Update the parser in your
.eslintrc.*
file (frombabel-eslint
to@babel/eslint-parser
) - Add the following to the
parserOptions
configuration in your.eslintrc.*
file:
requireConfigFile: false,
babelOptions: {
presets: ["@babel/preset-react"]
}
Longer version
First, switch out the Babel eslint plugin by removing babel-eslint
and installing @babel/eslint-parser
:
npm uninstall babel-eslint
npm install @babel/eslint-parser -D
If you’re not running npm 7 (Node15) you will also need to add
@babel/core
, which is a peer dependency of@babel/eslint-parser
. From npm 7 peer dependencies are installed by default.
And then update the parser (in your .eslintrc.*
file):
- parser: 'babel-eslint',
+ parser: '@babel/eslint-parser',
If you run eslint now you’ll now get an error about config files:
0:0 error Parsing error: No Babel config file detected for C:tempsite-testtailwind.config.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files
To fix this we need to modify parserOptions
:
+ parserOptions: {
+ requireConfigFile: false,
+ },
And now if we run eslint again? An error parsing React code (specifically jsx), which helpfully tells us how to fix the issue:
18:4 error Parsing error: C:tempsite-testsrctemplatesblog-post.js: Support for the experimental syntax 'jsx' isn't currently enabled (18:5):
16 |
17 | return (
> 18 | <Layout>
| ^
Add @babel/preset-react (https://git.io/JfeDR) to the 'presets' section of your Babel config to enable transformation.
If you want to leave it as-is, add @babel/plugin-syntax-jsx (https://git.io/vb4yA) to the 'plugins' section to enable parsing
So let’s install the plugin:
npm install @babel/preset-react -D
And then update our parserOptions to pass this option through to Babel:
parserOptions: {
requireConfigFile: false,
+ babelOptions: {
+ presets: ["@babel/preset-react"],
+ },
},
And we’ll finally be able to run eslint!