React-app-rewired: Production build is empty

Created on 8 Feb 2019  路  5Comments  路  Source: timarney/react-app-rewired

I've followed this tutorial in order to add support for Workers on my CRA.

I had to modify the config-overrides.js, which now looks like this:

module.exports = function override(config, env) {
    config.module.rules.push({
        test: /\.worker\.js$/,
        use: { loader: 'worker-loader' }
      });
    config.output['globalObject'] = 'this';
    return config;
}

And everything runs smoothly while testing. But just as I was trying to create a production build I realized the build directory contains nothing more than the favicon.ico and the manifest.json file.

What could I be missing?

Most helpful comment

I solved this issue already, I just forgot about closing it, I'm sorry.

The problem in my case is that I was using react-app-rewired in order to create some WebWorkers in my react app using the worker-loader lib. The issue was solved by adding a lint line at the lines of code which made reference to the self keyword. The line itself is this one:

  self.postMessage(result); // eslint-disable-line no-restricted-globals

I don't think this was an issue with react-app-rewired itself, but since I got no logs or anything I could not rule that out. Where do I get those by the way?

All 5 comments

@bilthon do you have any logs from the build?

I solved this issue already, I just forgot about closing it, I'm sorry.

The problem in my case is that I was using react-app-rewired in order to create some WebWorkers in my react app using the worker-loader lib. The issue was solved by adding a lint line at the lines of code which made reference to the self keyword. The line itself is this one:

  self.postMessage(result); // eslint-disable-line no-restricted-globals

I don't think this was an issue with react-app-rewired itself, but since I got no logs or anything I could not rule that out. Where do I get those by the way?

When you run npm build, npm start, or npm test, you should be able to see the logs on the console. It's strange if you have no logs showing up but glad you figured it out. Let us know if anything else comes up. Thanks!

I'm getting exactly this issue too, and the eslint thing fixed it! Wooohooo. Thank you @leifdejong .

There can be other ESLint errors than that, and the bigger problem is that when we are using react-app-rewired with worker-loader - during build the ESLint do not show any output for worker files.

For me, workaround looks like this, run this command from your app dir:

 npx eslint ./PATH_TO_YOUR_WORKER_FILE -c ./node_modules/eslint-config-react-app/index.js

This will show any errors preventing build. Have a good coding.

Also, for the restricted globals, it's easier to just put /* eslint no-restricted-globals: 0 */ on top of the worker file.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lyudad picture lyudad  路  6Comments

huygn picture huygn  路  3Comments

brendonco picture brendonco  路  3Comments

InsOpDe picture InsOpDe  路  5Comments

xiaoxiangmoe picture xiaoxiangmoe  路  3Comments