[英]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.