未知选项:Babel和ESLint设置中的. module.

gt0wga4j  于 11个月前  发布在  Babel
关注(0)|答案(1)|浏览(191)

我在一个React项目中遇到了Babel和ESLint设置的问题。当我运行ESLint时,我得到了以下错误:

Line 0: Parsing error: Unknown option: .module. Check out https://babeljs.io/docs/en/babel-core/#options for more information about options

字符串
以下是我的配置文件的相关部分:
babel.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-react", [
              "@babel/preset-env",
              {
                "useBuiltIns": "entry",
                "corejs": "3.22"
              }
            ]],
            plugins: ["@babel/plugin-proposal-optional-chaining"],
          },
        },
      },
    ],
  },
};


.eslintrc公司

module.exports = {
      parser: "@babel/eslint-parser",
      parserOptions: {
        requireConfigFile: false,
        babelOptions: {
          presets: ["@babel/preset-env", "@babel/preset-react"],
        },
      },
    };


我已经检查了Babel文档,但无法找到解决方案。任何帮助解决此问题将不胜感激。谢谢!
这是我的package.json文件

{
      "name": "memory",
      "version": "0.1.0",
      "private": true,
      "dependencies": {
        "@softbind/react-hooks": "^0.0.3",
        "@testing-library/jest-dom": "^5.17.0",
        "@testing-library/react": "^13.4.0",
        "@testing-library/user-event": "^13.5.0",
        "lodash.shuffle": "^4.2.0",
        "normalize.css": "^8.0.1",
        "prop-types": "^15.8.1",
        "react": "^18.2.0",
        "react-dom": "^18.2.0",
        "react-helmet": "^6.1.0",
        "react-router-dom": "^6.20.0",
        "react-scratchcard": "^1.1.2",
        "react-scripts": "^5.0.1",
        "react-sound": "^1.2.0",
        "react-spring": "^9.7.3",
        "react-tsparticles": "^2.12.2",
        "styled-components": "^6.1.1",
        "tailwind.macro": "^0.5.10",
        "tsparticles": "^2.12.0",
        "tsparticles-slim": "^2.12.0",
        "typescript": "^5.3.2",
        "use-machine": "^1.1.3",
        "web-vitals": "^2.1.4",
        "xstate": "^4.38.3"
      },
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
      },
      "eslintConfig": {
        "extends": [
          "react-app",
          "react-app/jest"
        ]
      },
      "browserslist": {
        "production": [
          ">0.2%",
          "not dead",
          "not op_mini all"
        ],
        "development": [
          "last 1 chrome version",
          "last 1 firefox version",
          "last 1 safari version"
        ]
      },
      "devDependencies": {
        "@babel/core": "^7.23.5",
        "@babel/plugin-proposal-optional-chaining": "7.21.0",
        "@babel/plugin-syntax-object-rest-spread": "^7.8.3",
        "@babel/preset-env": "7.23.5",
        "@babel/preset-react": "7.23.3",
        "@iconify/icons-raphael": "1.2.3",
        "@iconify/react": "4.1.1",
        "babel-plugin-macros": "3.1.0",
        "babel-plugin-styled-components": "2.1.4",
        "eslint": "^8.54.0",
        "eslint-config-airbnb": "19.0.4",
        "eslint-config-prettier": "9.0.0",
        "eslint-plugin-import": "2.29.0",
        "eslint-plugin-jsx-a11y": "6.8.0",
        "eslint-plugin-prettier": "5.0.1",
        "eslint-plugin-react": "7.33.2",
        "husky": "8.0.3",
        "lint-staged": "15.1.0",
        "prettier": "3.1.0"
      }
    }

j8yoct9x

j8yoct9x1#

您的babel.config.js不包含Babel工具可以处理的有效配置。有关其配置文件应该是什么样子的更多信息可以在here中找到。相反,您包含的内容应该在Webpack config中使用。如果您将babel.config.js重命名为webpack.config.js,它可能会工作(假设你使用的是Webpack)。如果你没有使用Webpack,你需要将配置转换成Babel可以处理的配置。比如:

module.exports = {
  presets: [
    "@babel/preset-react",
    [
      "@babel/preset-env",
      {
        useBuiltIns: "entry",
        corejs: "3.22",
      }
    ]
  ],
  plugins: ["@babel/plugin-proposal-optional-chaining"]
};

字符串
此外,由于您的配置文件很简单,实际上并没有使用JS,因此可以将其转换为JSON配置文件,如babel.config.json

相关问题