-
-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
react-scripts build fails to output any files when using workerize-loader #8014
Comments
@mattdarveniza this seems to be a case of webpack silently failing, which I've run into before, so I thought I'd share what I found. Starting with your reproducible demo, I ejected so as to be able to control the build script. Adding this line to the build script lets us see some more info from webpack: diff --git a/scripts/build.js b/scripts/build.js
--- a/scripts/build.js
+++ b/scripts/build.js
@@ -145,6 +145,7 @@ function build(previousFileSizes) {
const compiler = webpack(config);
return new Promise((resolve, reject) => {
compiler.run((err, stats) => {
+ console.log(stats.toString())
let messages;
if (err) {
if (!err.message) { Now if you run
Full Output
So for some reason the eslint error in the worker is causing the webpack process to stop, but webpack doesn't output any errors, so the build continues like normal. I'm not sure why that is. If you add an eslint-disable to the I don't know enough about webpack to know why the webpack build didn't return an error, hopefully someone else might be able to explain more on that because I'm very curious, too. |
Thanks @garrettjstevens, that's a really good tip for debugging webpack issues. Bizarre that it gives you no output by default. I wonder if that's due to the nature of worker files, or something more general in CRA. More investigating to do... |
diff --git a/scripts/build.js b/scripts/build.js
index ec479fa..b74937b 100644
--- a/scripts/build.js
+++ b/scripts/build.js
@@ -140,6 +140,7 @@ module.exports = function(NODE_ENV) {
} else {
messages = formatWebpackMessages(stats.toJson({ all: false, warnings: true, errors: true }));
}
if (messages.errors.length) {
// Only keep the first error. Others are often indicative
// of the same problem, but confuse the reader with noise.
@@ -148,6 +149,12 @@ module.exports = function(NODE_ENV) {
}
return reject(new Error(messages.errors.join("\n\n")));
}
+
+ if (stats.hasErrors()) {
+ return reject(new Error(stats.toString()));
+ }
+ |
Thanks @franckXu, what you posted helped me do some more research and realize there is already a PR that would fix this: #6286 Basically, that PR checks for error messages in webpack children as well as just top-level errors, so in the above example the eslint error would have showed instead of the build failing silently. |
Given that's the root of this issue, I'll close this issue in favour of that PR |
@garrettjstevens thanks for finding that, just want to comment my gratitude this was very confusing for me but your solution fixes it and just saved me a lot of time and worry. |
Describe the bug
I know that technically web workers aren't officially supported in react-scripts yet, however given that we have issues like #7741 supported, and the discussion in #5886 I would have expected this to work.
Currently
workerize-loader
works within react-scripts by using theworkerize-loader!./your/file
webpack syntax. This works perfectly well in development, however when it comes to a build, this seems to break the build. Instead of the expected file chunks being output, it results in no files being output, like below:Note the empty section after
File sizes after gzip
. After this, thebuild
directly only contains files copied frompublic
, no build artefacts.Did you try recovering your dependencies?
Yes, reproducible on fresh install.
Which terms did you search for in User Guide?
Not relevant
Environment
Project installed via
npm
Steps to reproduce
I've produced a freshly squeezed reproducible test case to illustrate this problem
npm install
,npm start
, and observe the button firing web worker code in devnpm run build
and observe no files being build into thebuild
directory.App.js
, and observe that it now builds as expected.Expected behavior
npm run build
should collect and build the project into thebuild
dirActual behavior
build
dir only contains assets copied frompublic
after a build.Reproducible demo
As linked above https://github.com/mattdarveniza/worker-cra-test
Extra Info
One other thing to note is that previously I've been running a forked version of react-scripts based on PR #5886 which uses
worker-loader
to load workers, based on react-scripts 3.0.0. Upgrading that fork to be up to date with3.2.0
seems to cause the same problem, so at a guess I'd say something has changed in the webpack config or webpack version that makes these worker plugins no longer... work (pardon the pun).I'm don't have a deep enough knowledge of react-script's webpack config to have much more insight than that unfortunately.
The text was updated successfully, but these errors were encountered: