解析错误:未检测到 Babel 配置文件

Dan*_*iel 32 node.js vue.js vuejs2

我正在尝试在 vue 中创建一个项目。但我在创建项目后遇到这个问题。

Parsing error: No Babel config file detected for C:\\HotelManagmet\clienthotel\babel.config.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files. 我无法解决它,我尝试重新安装node.js和Visual Studio代码,但问题仍然存在。已尝试运行 npmauditfix --force 但不幸的是结果是相同的。有人知道它可能是什么吗?

pra*_*eep 52

我遇到了同样的问题,此更改解决了问题。在您的.eslintrc.js文件中,添加requireConfigFile: false

parserOptions: {
  parser: '@babel/eslint-parser',
  requireConfigFile: false, // <== ADD THIS
  ecmaVersion: 2018, // Allows for the parsing of modern ECMAScript features
  sourceType: 'module' // Allows for the use of imports
}
Run Code Online (Sandbox Code Playgroud)

  • 注意:`parser: '@babel/eslint-parser',`需要在`parserOptions`之外定义 (11认同)

小智 8

解决方案1

最重要的是:babel.config.js应该在你的根目录中。这意味着如果您有这样的结构: 在此处输入图像描述

root directory
    --your project1
    |
    |--src
    |--nodemodules
    |--babel.config.js
    --your project2
    |
    |--src
    |--nodemodules
    |--babel.config.js
Run Code Online (Sandbox Code Playgroud)

如果你运行该项目,它会显示错误。所以如果你想运行project1或project2,只需打开它,然后确保它是根目录。

解决方案2

打开 .eslintrc.js,并更改 root 值,例如:

root:'',
Run Code Online (Sandbox Code Playgroud)


San*_*AJI 5

 "parserOptions": {
      "parser": "@babel/eslint-parser",
      "requireConfigFile": false // add this in package.json for Vue3
    },
Run Code Online (Sandbox Code Playgroud)