question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Typescript errors with Webpack 5

See original GitHub issue

Webpack 5 (5.0.0-beta.16) does not export Plugin, which cause type-checking and builds to fail with:

node_modules/nodemon-webpack-plugin/dist/index.d.ts:3:12 - error TS2459: Module '"......./node_modules/webpack/types"' declares 'Plugin' locally, but it is not exported.

3   import { Plugin } from 'webpack';
             ~~~~~~

  node_modules/webpack/types.d.ts:5126:19
    5126 declare interface Plugin {
                           ~~~~~~
    'Plugin' is declared here.

node_modules/schema-utils/declarations/validate.d.ts:2:34 - error TS2307: Cannot find module 'json-schema'.

2 export type JSONSchema4 = import('json-schema').JSONSchema4;
                                   ~~~~~~~~~~~~~

node_modules/webpack/types.d.ts:62:8 - error TS2307: Cannot find module 'estree'.

62 } from "estree";

Related:

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:27 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
Izhakicommented, Mar 25, 2021

The typings issue was declared by the WebPack team as a breaking change between v4 and v5.

We have two options:

  1. Split the plugin.
  2. Create our own types (like html-webpack-plugin did).

Second option seems far more reasonable to me.

Will attempt fix in due course.

0reactions
Izhakicommented, Mar 29, 2021
// This throws an error with my setup and TypeScript config.
import NodemonPlugin from 'nodemon-webpack-plugin';

I’m afraid this has to do with the whole CommonJS/ES6 mismatch, and I’ve documented this in the type definitions:

// We prioritise supporting CommonJS than ES6 syntax here.
// Typescript users will have to add `esModuleInterop` in `compilerOptions`.
// https://www.typescriptlang.org/docs/handbook/modules.html#export--and-import--require
export = NodemonPlugin;

Basically, you need to choose between CommonJS (export =) and ES6 (export default). If you opt for the latter, than CommonJS scripts will have to import the plugin like this (note .default):

const NodemonPlugin = require('nodemon-webpack-plugin').default; 

I’ve prioritise the CommonJS export based on a (rather reasonable in my view) assumption that most users don’t have their webpack.config.js transpiled.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack 5 watch not failing on error · Issue #1204 - GitHub
I expect webpack to fail when trying to bundle my files when typescript/ts-loader detects an error. This worked fine so far when I...
Read more >
Webpack is not failing on TypeScript error - Stack Overflow
Since I upgraded to version 5, webpack does not fail on a TypeScript error. Here is my scenario: index.ts (entry point):
Read more >
TypeScript - webpack
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. In this guide we will learn how to integrate TypeScript with...
Read more >
Using webpack with TypeScript - LogRocket Blog
Learn how to use webpack to compile TypeScript to JavaScript and bundle ... LogRocket records console logs, JavaScript errors, stacktraces, ...
Read more >
Compiling and bundling TypeScript libraries with Webpack
TypeScript libraries in JavaScript applications. I found that writing library and application code are two pretty different experiences. They serve different ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found