I've recently attempted to update one of my projects to webpack v4, in addition to a couple of other updates. One of them broke my build with a curious error:
TypeError: readFileFn is not a function
After debugging things a bit, I figured out that one of the plugins I'm using attempts to access compiler.inputFileSystem._readFile, which is present in the apply phase, but was no longer existing when it came to emit.
Playing a bit with the configuration, I was able to point out that this modification was made by the AngularCompilerPlugin, which is part of @ngtools/webpack. More precisely, it happens due to the decoration performed by it:
|
compiler.hooks.environment.tap('angular-compiler', () => { |
|
compiler.inputFileSystem = new VirtualFileSystemDecorator( |
|
compiler.inputFileSystem, this._compilerHost); |
|
compiler.watchFileSystem = new VirtualWatchFileSystemDecorator(compiler.inputFileSystem); |
|
}); |
After this,
compiler.inputFileSystem._readFile is no longer available. Thus, the decoration breaks the API available on
compiler.inputFIleSystem and makes plugins relying on it fail.
Versions
- No
ng version, since it's a custom setup
- Node 8.10.0
- NPM 5.7.1
- Yarn 1.5.1
- @ngtools/webpack 1.10.2
- Ubuntu 16.04
Repro steps
Observed behavior
The last command will fail with an error like this.
TypeError: readFileFn is not a function
(See the build output here: https://travis-ci.org/DorianGrey/ng-webpack-template/jobs/357274315)
Desired behavior
Decoration or encapsulation of any of these internal parts of webpack should not break their available API, regardless of potentially intended privacy (suppose the leading _ might tend in this direction).
Mention any other details that might be useful (optional)
I've also tried the latest beta version of the @ngtools/webpack plugin and made a cross-check against webpack v3, but neither made any difference.
Not sure if this is of any help or use, but the affected plugin in my case is the workbox-webpack-plugin, which changed it's implementation and behavior in v3.
https://github.com/GoogleChrome/workbox/blob/fa4d8b7dab2b0680c15d6057c12fd9ec9f0932c4/packages/workbox-webpack-plugin/src/inject-manifest.js#L150-L154
Suppose that's why this problem did not raise before.
I've recently attempted to update one of my projects to
webpackv4, in addition to a couple of other updates. One of them broke my build with a curious error:After debugging things a bit, I figured out that one of the plugins I'm using attempts to access
compiler.inputFileSystem._readFile, which is present in theapplyphase, but was no longer existing when it came toemit.Playing a bit with the configuration, I was able to point out that this modification was made by the
AngularCompilerPlugin, which is part of@ngtools/webpack. More precisely, it happens due to thedecorationperformed by it:angular-cli/packages/@ngtools/webpack/src/angular_compiler_plugin.ts
Lines 549 to 553 in d1b22d0
After this,
compiler.inputFileSystem._readFileis no longer available. Thus, the decoration breaks the API available oncompiler.inputFIleSystemand makes plugins relying on it fail.Versions
ngversion, since it's a custom setupRepro steps
yarnyarn buildObserved behavior
The last command will fail with an error like this.
(See the build output here: https://travis-ci.org/DorianGrey/ng-webpack-template/jobs/357274315)
Desired behavior
Decoration or encapsulation of any of these internal parts of
webpackshould not break their available API, regardless of potentially intended privacy (suppose the leading_might tend in this direction).Mention any other details that might be useful (optional)
I've also tried the latest beta version of the
@ngtools/webpackplugin and made a cross-check againstwebpackv3, but neither made any difference.Not sure if this is of any help or use, but the affected plugin in my case is the
workbox-webpack-plugin, which changed it's implementation and behavior in v3.https://github.com/GoogleChrome/workbox/blob/fa4d8b7dab2b0680c15d6057c12fd9ec9f0932c4/packages/workbox-webpack-plugin/src/inject-manifest.js#L150-L154
Suppose that's why this problem did not raise before.