4

Software involved:

  • webpack 4.8.3
  • typescript 2.8.3
  • ts-loader 4.3.0

Webpack configuration:

rules: [
    {
        test: /\.ts(x?)$/,
        exclude: /node_modules/,
        use: ['ng-annotate-loader', 'ts-loader']
    },
    ...
]

This compiles my project fine on a single build (webpack --mode development).

However, it starts to produce errors when building in watch mode:

$ webpack --progress --watch --mode development
Webpack is watching the files…

Hash: e8f3fc158b2b6feaad07                                                                  
Version: webpack 4.8.3
Time: 75713ms
Built at: 05/15/2018 3:25:27 PM
          Asset       Size      Chunks             Chunk Names
          ...

(The build is fine. Now I change one file, and it rebuilds:)

[./ts/foo/foo.ts] 3.82 KiB {foo} [built] [1 error]
[./ts/foo/controllers/bar.ts] 3.8 KiB {baz} {foo} [built]
[./ts/foo/baz.ts] 4.21 KiB {baz} [built] [1 error]
    + 668 hidden modules

ERROR in .../ts/foo/foo.ts
./ts/foo/foo.ts
[tsl] ERROR in .../ts/foo/foo.ts(84,9)
      TS2554: Expected 0 arguments, but got 1.

ERROR in .../ts/foo/baz.ts
./ts/foo/baz.ts
[tsl] ERROR in .../ts/foo/baz.ts(105,9)
      TS2554: Expected 0 arguments, but got 1.

The lines it refers to are all lines containing console.log calls, e.g.:

console.log(`Using locale ${locale}`);

Again, if I abort the watch and build from scratch, it works just fine. What's the problem here?

For testing I have removed ng-annotate-loader; no change.
This started happening after upgrading the build toolchain from Webpack 3 to 4 with associated upgrades to Typescript from 2.3.x. In the old versions build --watch works fine.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • Possible to get a minimal reproducible repo? – Tarun Lalwani May 18 '18 at 08:25
  • Yeah, that's a bit tricky… :-/ I may try to reproduce that from scratch when I have some time, but for now my generic question would be any hint why a re-build in watch mode would behave any differently at all than a build from scratch. That may help me narrow down the problem. – deceze May 18 '18 at 08:28

1 Answers1

0

I think that the problem is related to webpack.NewWatchingPlugin (the default watching plugin), but you can force webpack to use the old file watching logic if you add new webpack.OldWatchingPlugin() plugin. The OldWatchingPlugin is more stable than NewWatchingPlugin.

There are a variety of reasons why webpack might not working properly:

  • If no files are outputted (with different hashes), it is likely a configuration issue, not a file watching issue.
  • Having not enough file watchers causes file watcher in Webpack won't recognize the changes.
Amirhossein Mehrvarzi
  • 18,024
  • 7
  • 45
  • 70
  • 1
    Looks like `OldWatchingPlugin` [has been removed a while ago](https://github.com/webpack/webpack/commit/e8e541c3fe1b4483c31afb8562956e36c79f0e27)… But I'll try to dick around with the watch plugin settings a bit to see if anything makes any difference. – deceze May 23 '18 at 09:02
  • @deceze, you might as well rename `d*ck` to `dig` :-) – Tarun Lalwani May 23 '18 at 10:55
  • Did you eventually find a solution? – Johan Lindskogen May 20 '20 at 15:45