Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TS Typing error: "This expression is not constructable." when esModuleInterop is false #65

Closed
fcaminada opened this issue Jan 20, 2021 · 1 comment · Fixed by #66
Closed

Comments

@fcaminada
Copy link

Bug Report

Hello, I am opening this issue as an follow-up to #16, which I believe still has issues with the TypeScript typing.
As I mentioned on my comment, it is not possible to correctly import this package with its current type exports if I use the esModuleInterop set as false.

  • Operating System:
  • Node Version: v14.15.1
  • NPM Version: 7.0.14
  • webpack Version: 5.11.0
  • eslint-webpack-plugin Version: 2.4.0
  • eslint version: 7.7.0
  • Typescript version: 4.0.1

Expected Behavior

Importing "eslint-webpack-plugin" should correctly return the ESLintWebpackPlugin class and I should be able to instantiate it with the following code;

import ESLintWebpackPlugin = require("eslint-webpack-plugin");
import * as ESLintWebpackPlugin from "eslint-webpack-plugin"; // Alternative import.
import ESLintWebpackPlugin from "eslint-webpack-plugin" // when using esModuleInterop: true
...
new ESLintWebpackPlugin({
    // Options.
});

Actual Behavior

Importing the default exports causes either a TS or a JS error when esModuleInterop is disabled, as I better explain on my comment here.

Code and Reproduction:

https://gist.github.com/fcaminada/7d2cc25c74c3b7bdfe43246190c5d57d

The solution would be to follow the same example as other plugins such as CssMinimizerPlugin, for instance.

@ValYouW
Copy link

ValYouW commented Mar 2, 2021

@ricardogobbosouza vscode ts type-check still gives an error on this when using require:

var ESLintWebpackPlugin = require('eslint-webpack-plugin');
new ESLintWebpackPlugin(); // error ts(2351)

Any idea? doesnt happen with other plugins (which use export = xxx instead of export default xxx in the declarations file)

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants