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

3mpgtkmj  于 5个月前  发布在  Webpack
关注(0)|答案(2)|浏览(60)

我有一个react原生Web应用程序。我尝试使用webpack.js.js文件运行该应用程序。
所以我安装了webpack和webpack-json。并在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.js.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。
问:如何解决这个问题?

fdx2calv

fdx2calv1#

我之前也遇到过同样的问题。你需要将requireConfigFile: false添加到你的.eslintrc.js文件中。

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

字符串

q9yhzks0

q9yhzks02#

.eslintrc.js中,添加:

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

字符串
如果没有,也添加:

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

相关问题