Skip to content

Commit 75521d9

Browse files
rootBr1an67
authored andcommitted
fix: detect memfs used by webpack-dev-server 4+
Webpack-dev-server 4+ uses memfs instead of memory-fs for in-memory filesystem. The memfs library creates a filesystem object with a __vol property that references the underlying Volume instance. This fix checks for the __vol property to detect memfs and returns null for bundleDir, which prevents the analyzer from trying to read bundle files from disk when they only exist in memory.
1 parent b3f44b0 commit 75521d9

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

src/BundleAnalyzerPlugin.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,17 @@ class BundleAnalyzerPlugin {
229229
}
230230

231231
getBundleDirFromCompiler() {
232-
const outputFileSystemConstructor =
232+
const outputFileSystem =
233233
/** @type {OutputFileSystem} */
234-
(/** @type {Compiler} */ (this.compiler).outputFileSystem).constructor;
234+
(/** @type {Compiler} */ (this.compiler).outputFileSystem);
235+
236+
// Detect `memfs` (used by webpack-dev-server 4+) by checking for the `__vol` property
237+
// Related: #471
238+
if (/** @type {{ __vol?: unknown }} */ (outputFileSystem).__vol) {
239+
return null;
240+
}
241+
242+
const outputFileSystemConstructor = outputFileSystem.constructor;
235243

236244
if (typeof outputFileSystemConstructor === "undefined") {
237245
return /** @type {Compiler} */ (this.compiler).outputPath;

0 commit comments

Comments
 (0)