代码之家  ›  专栏  ›  技术社区  ›  mightycode Newton

如何解决错误:webpack.config.js,未检测到“”的Babel配置文件

  •  0
  • mightycode Newton  · 技术社区  · 2 年前

    我有一个react原生网络应用程序。我试着用webpack.config.js文件运行这个应用程序。

    所以我安装了webpack和webpack-cli。并在package.json中添加了以下内容:

    {
        "name": "app",
        "version": "1.0.0",
        "main": "node_modules/expo/AppEntry.js",
        "scripts": {
            "start": "expo start, react-app-rewired start ",
            "android": "expo start --android",
            "ios": "expo start --ios",
            "web": "expo start --web",
            "eject": "expo eject",
            "lint": "eslint . --ext .js",
            "postinstall": "patch-package",
            "build": "webpack --config webpack.config.js",
            "start-webpack": "webpack-dev-server --mode production --open"
        },
    
        "parserOptions": {
            "parser": "@babel/eslint-parser",
            "requireConfigFile": false
        },
    

    webpack.config.js文件如下所示:

    const createExpoWebpackConfigAsync = require("@expo/webpack-config");
    
    
    module.exports = async function (env, argv) {
        const config = await createExpoWebpackConfigAsync(env, argv);
    
    
        
        if (config.mode === "production") {
            config.devServer.compress = false;
        }
    
        return config;
    };
    

    这是eslintrc文件:

    {
        "extends": "@react-native-community",
    
        "rules": {
            "prettier/prettier": ["error", { "printWidth": 120 }],
            "react/react-in-jsx-scope": "off",
            "quotes": [2, "double", { "avoidEscape": true }]
        }
    }
    
    

    但我仍然会遇到这样的错误:

    Parsing error: No Babel config file detected for C:\repos\Dierenwelzijn\DWL_frontend\webpack.config.js. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.eslint
    

    但该文件位于此url。

    问题:如何解决这个问题?

    2 回复  |  直到 2 年前
        1
  •  2
  •   Joseph    2 年前

    在您的 .eslintrc.js ,添加:

    "eslint.workingDirectories": [
            {"mode": "auto"}
        ],
    

    如果没有,也添加:

    parserOptions: {
      parser: '@babel/eslint-parser',
      requireConfigFile: false,
      ...
    }
    
        2
  •  1
  •   Damodar Hegde    2 年前

    我早些时候也遇到过同样的问题。您需要添加 requireConfigFile: false 给你 .eslintrc.js 文件

    parserOptions: {
      parser: '@babel/eslint-parser',
      requireConfigFile: false, // ADD THIS
      ...
    }