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

3mpgtkmj  于 2024-01-08  发布在  Webpack
关注(0)|答案(2)|浏览(189)

我有一个react原生Web应用程序。我尝试使用webpack.js.js文件运行该应用程序。
所以我安装了webpack和webpack-json。并在package.json中添加了以下内容:

  1. {
  2. "name": "app",
  3. "version": "1.0.0",
  4. "main": "node_modules/expo/AppEntry.js",
  5. "scripts": {
  6. "start": "expo start, react-app-rewired start ",
  7. "android": "expo start --android",
  8. "ios": "expo start --ios",
  9. "web": "expo start --web",
  10. "eject": "expo eject",
  11. "lint": "eslint . --ext .js",
  12. "postinstall": "patch-package",
  13. "build": "webpack --config webpack.config.js",
  14. "start-webpack": "webpack-dev-server --mode production --open"
  15. },
  16. "parserOptions": {
  17. "parser": "@babel/eslint-parser",
  18. "requireConfigFile": false
  19. },

字符串
webpack.js.js文件看起来:

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


这是eslintrc文件:

  1. {
  2. "extends": "@react-native-community",
  3. "rules": {
  4. "prettier/prettier": ["error", { "printWidth": 120 }],
  5. "react/react-in-jsx-scope": "off",
  6. "quotes": [2, "double", { "avoidEscape": true }]
  7. }
  8. }


但我还是犯了这个错误:

  1. 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文件中。

  1. parserOptions: {
  2. parser: '@babel/eslint-parser',
  3. requireConfigFile: false, // ADD THIS
  4. ...
  5. }

字符串

q9yhzks0

q9yhzks02#

.eslintrc.js中,添加:

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

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

  1. parserOptions: {
  2. parser: '@babel/eslint-parser',
  3. requireConfigFile: false,
  4. ...
  5. }

相关问题