Compiler.outputFileSystem.constructor of Webpack can be undefined in webpack 5.0#384
Compiler.outputFileSystem.constructor of Webpack can be undefined in webpack 5.0#384iamssen wants to merge 3 commits intowebpack:masterfrom iamssen:master
Conversation
| return null; | ||
| default: | ||
| return this.compiler.outputPath; | ||
| if (this.compiler.outputFileSystem.constructor) { |
|
I don't know exactly. In webpack 4.x, outputFileSystem is set to However, in webpack 5.x, As I checked, after webpack 5.x, it seems that I couldn't find a way to check if the See more: |
|
Can we have some sort of spec that he code works for all versions of webpack we have? You can see an example of testing different kinds of webpack configurations here: Remember to check that a new test case would break without the fix here. |
| } | ||
| // TODO Can we check the outputFileSystem is graceful-fs or memfs on webpack 5.x? | ||
| // If avaliable, we can return null if the outputFileSystem is memfs. | ||
| return this.compiler.outputPath; |
There was a problem hiding this comment.
The thing is in webpack 5 it will return this.compiler.outputPath even in dev mode (when webpack-dev-server is used) and will try to parse compiled bundle which is not there.
Seems like we need some other way to detect non-physical file systems now.
|
I cannot reproduce a crash with the latest webpack-dev-server beta.
My setup: https://github.com/ludofischer/bundle-analyzer-webpack5 @iamssen Does the error occur when using webpack-dev-server? In your pull request https://github.com/rocket-hangar/rocket-scripts/pull/25/files, |
|
I can reproduce this error in Jest. Here's a minimal repro:
(noop-entry.js is just an empty file)
It's unclear why this error is happening right now -- I will note though that this test would pass (ie. Webpack Bundle Analyzer starts up and serves data) under Webpack 4 and the v3 branch of this library. @alexander-akait @th0r let me know if you'd like me to file an issue instead of adding stuff onto this closed PR. PS: the |
|
Can you open a new pull request with the failing test so we can see the failure in this repos CI, too? :) |
I'm not able to reproduce in this repo itself :/ ( I added a print in NodeEnvironmentPlugin and observed the |
|
Somebody change |
|
@alexander-akait: I added a console log statement in NodeEnvironmentPlugin where And here |
|
Can you show and run |
It seems This output is from my repro example above, so yarn why is just going to give a direct dependency: I've tried using webpack@5.4.0 since that's what this repo tests, but no success either. |
|
Do you use https://github.com/TypeStrong/fork-ts-checker-webpack-plugin? Maybe you can provide list of plugins? |
|
@alexander-akait can you take a look at my minimal repro example above in this PR: #384 (comment) No plugins other than this one |
Wrong link? |
Not sure why the link is broken, GitHub web UI bug maybe. I've quoted the original comment |
|
Give me 5-15 minutes, I will look |
|
Reproduced, thanks, investigate |
|
Yes, it is bug, fix: getBundleDirFromCompiler() {
if (typeof this.compiler.outputFileSystem.constructor === 'undefined') {
return this.compiler.outputPath;
}
switch (this.compiler.outputFileSystem.constructor.name) {
case 'MemoryFileSystem':
return null;
// Detect AsyncMFS used by Nuxt 2.5 that replaces webpack's MFS during development
// Related: #274
case 'AsyncMFS':
return null;
default:
return this.compiler.outputPath;
}
} |
|
/cc @valscion need your attention |
|
We would really like to have a failing test case before the change so we won't regress this behavior in the future. I tried making up one, but am unable to do it. Is the only way possible to replicate this issue in a test by using Jest? |
|
@valscion Example above #384 (comment) 😕 Just run it and you will see the problem |
|
And look at types, there is not |
|
Yeah, I'm just having a hard time wrapping the reproduction to a test case that I could get it to fail in CI... |
|
.cc @valscion hm, put it under todo and will add it late, package is not working, it is more priority |
|
Also you can use test it using |
|
Would be great to add a testcase to prevent regressions in a follow up since this is blocking a webpack 5 migration for me 👍 |
|
@alexander-akait : I wrote a PR with your fix in #447 |
I tried this one, but maybe I'm doing something wrong as these steps don't give me the failure that I'm supposed to see. We can go with the PR in #447 but as long as there are no tests, it's possible that we'll break the fix even in a patch release as there is no way we can make sure that this fix doesn't suddenly stop working unless we have test coverage for that. |
|
The fix in #447 has been released in v4.4.2 🎉 |
After webpack 5.0 update
BundleAnalyzerPlugin.getBundleDirFromCompiler()throws errors.Compiler.outputFileSystem.constructoris undefined.After this fix, my configuration works fine in the webpack 5.0.