简体   繁体   English

类型错误:类构造函数 ESLintWebpackPlugin 不能在没有“new”的情况下被调用

[英]TypeError: Class constructor ESLintWebpackPlugin cannot be invoked without 'new'

I am building a React with Redux environment, and I keep getting this error message when I run npm start:我正在使用 Redux 环境构建 React,并且在运行 npm start 时不断收到此错误消息:

ERROR in ./src/index.js
Module build failed (from ./node_modules/eslint-webpack-plugin/dist/cjs.js):
TypeError: Class constructor ESLintWebpackPlugin cannot be invoked without 'new'

I've seen in previous questions the answer is to include "esmodules": true so here's the relevant part of my package.json:我在之前的问题中看到答案是包含"esmodules": true所以这是我的 package.json 的相关部分:

"babel": {
    "presets": [
      [
        "@babel/preset-env",
        {
          "targets": {
            "esmodules": true
          }
        }
      ],
      "@babel/preset-react"
    ],
    "plugins": [
      "@babel/plugin-proposal-class-properties"
    ]
}

Also here is my index.js file, although I don't think there's anything in there that should be offending.这里也是我的 index.js 文件,虽然我不认为那里有什么应该冒犯的地方。

import React from 'react';
import { render } from 'react-dom';
import { BrowserRouter as Router } from 'react-router-dom';
import 'bootstrap/dist/css/bootstrap.min.css';
import App from './components/App';
import './index.css';
import configureStore from './redux/configureStore';
import { Provider as ReduxProvider } from 'react-redux';

const store = configureStore();

render(
    <ReduxProvider store={store}>
        <Router>
            <App />
        </Router>
    </ReduxProvider>,
    document.getElementById('app'),
);

This is probably related to the package versions that you use for eslint plugin and webpack.这可能与您用于 eslint 插件和 webpack 的包版本有关。 I upgraded the eslint in my project and have the same issue.我在我的项目中升级了 eslint 并遇到了同样的问题。

This same error came up for me while upgrading from eslint 6.8.0 to eslint 8 .eslint 6.8.0升级到eslint 8时,我遇到了同样的错误。 During the upgrade, I switched from babel-eslint to @babel/eslint-parser , and from eslint-loader to eslint-webpack-plugin .在升级过程中,我从babel-eslint切换到@babel/eslint-parser ,从eslint-loader切换到eslint-webpack-plugin

In my webpack.config.js , I (mistakenly and naively) changed from:在我的webpack.config.js ,我(错误地和天真地)从:

module.exports = {
  ...

  module: {
    rules: [
      {
        test: /\.js$/,
        include: Path.resolve(__dirname, '../src'),
        enforce: 'pre',
        loader: 'eslint-loader',         // <== NOTE
        options: {
          emitWarning: true,
        },
      },
      {
        test: /\.js$/,
        include: Path.resolve(__dirname, '../src'),
        loader: 'babel-loader',
        exclude: /node_modules/,
        options: {
          sourceType: 'unambiguous',
        },
      },
    ],
  },
};

to:到:

module.exports = {
  ...

  module: {
    rules: [
      {
        test: /\.js$/,
        include: Path.resolve(__dirname, '../src'),
        enforce: 'pre',
        loader: 'eslint-webpack-plugin', // <== UPDATED
        exclude: /node_modules/,         // <== UPDATED
        options: {
          emitWarning: true,
        },
      },
      {
        test: /\.js$/,
        include: Path.resolve(__dirname, '../src'),
        loader: 'babel-loader',
        exclude: /node_modules/,
        options: {
          sourceType: 'unambiguous',
        },
      },
    ],
  },
};

That DID NOT WORK .没有用 In fact, I believe this is what caused the Class constructor ESLintWebpackPlugin cannot be invoked without 'new' error to arise.事实上,我相信这是导致Class constructor ESLintWebpackPlugin cannot be invoked without 'new'错误的Class constructor ESLintWebpackPlugin cannot be invoked without 'new'

When I entirely removed the eslint-webpack-plugin entry from module: { rules: [ ... ] } section, and instead invoked the eslint-webpack-plugin (per its documentation) with:当我从module: { rules: [ ... ] }部分完全删除eslint-webpack-plugin条目时,而是调用了eslint-webpack-plugin (根据其文档):

...
const ESLintPlugin = require('eslint-webpack-plugin');

const myEslintOptions = {
  extensions: [`js`, `jsx`, `ts`],
  exclude: [`node_modules`],
};

module.exports = {
  ...
  plugins: [
    ...
    new ESLintPlugin(myEslintOptions),
    ...
  ],

  ...
  module: {
    rules: [
      {
        test: /\.js$/,
        include: Path.resolve(__dirname, '../src'),
        loader: 'babel-loader',
        exclude: /node_modules/,
        options: {
          sourceType: 'unambiguous',
        },
      },
    ],
  },
};

then the ...cannot be invoked without 'new' error finally disappeared.那么...cannot be invoked without 'new'错误终于消失了。 Lots of trial and error... webpack is powerful but not the most straightforward tool!大量的试验和错误...... webpack很强大,但不是最简单的工具!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError: Class 构造函数 MongoStore 不能在没有 'new' 的情况下被调用 - TypeError: Class constructor MongoStore cannot be invoked without 'new' 错误TypeError:如果没有在Ionic 4中使用“ new”,则无法调用类构造函数EventEmitter - ERROR TypeError: Class constructor EventEmitter cannot be invoked without 'new' in Ionic 4 Uncaught TypeError:类构造函数Hero不能在没有“ new”的情况下调用 - Uncaught TypeError: Class constructor Hero cannot be invoked without 'new' TypeError:如果没有“ new”,则无法调用类构造函数分页 - TypeError: Class constructor Pagination cannot be invoked without 'new' 类型错误:类构造函数 Wia 不能在没有“new”的情况下被调用 - TypeError: Class constructor Wia cannot be invoked without 'new' TypeError: Class 构造函数客户端不能在没有'new'的情况下被调用 - TypeError: Class constructor Client cannot be invoked without 'new' 反应 - 未捕获的类型错误:Class 构造函数 Firebase 不能在没有“新”的情况下调用 - React - Uncaught TypeError: Class constructor Firebase cannot be invoked without 'new' TypeError: Class 构造函数文档不能在没有'new'的情况下被调用 - TypeError: Class constructor Document cannot be invoked without 'new' 未捕获的类型错误:类构造函数 ScratchStorage 不能在没有“new”的情况下被调用 - Uncaught TypeError: Class constructor ScratchStorage cannot be invoked without 'new' TypeError: Class 构造函数 DatabaseError 不能在没有'new'的情况下被调用 - TypeError: Class constructor DatabaseError cannot be invoked without 'new'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM