question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CRACO, worker-plugin, and, react-refresh-webpack-plugin

See original GitHub issue

I’ll start by being honest - I’m not sure which repo this issue truly belongs to but I’ll start here.

I use CRACO to achieve a few things, including enabling web workers.

This is my config prior to react-scripts 4. Worked great

const { whenProd, addBeforeLoader, loaderByName } = require("@craco/craco");
const WorkerPlugin = require('worker-plugin');

module.exports = {
  webpack: {
    configure: function(webpackConfig) {
      // some stuff

      return webpackConfig;
    },
    plugins: [
      new WorkerPlugin(),
    ],
  },
};

Since updating everything, I’ve encountered some issues.

image

The config I’ve attempted (and some variations on)

const { whenProd, addBeforeLoader, loaderByName } = require("@craco/craco");
const WorkerPlugin = require('worker-plugin');

module.exports = {
  webpack: {
    configure: function(webpackConfig) {
      // some stuff

      return webpackConfig;
    },
    plugins: [
      new WorkerPlugin({
        globalObject: 'this',
        plugins: [
          'react-refresh-webpack-plugin'
        ]
      }),
    ],
  },
};

So this error is obviously to do with react-refresh-webpack-plugin and I’ve tried to work out how to trick it into doing the right thing but no luck.

I found https://github.com/pmmmwh/react-refresh-webpack-plugin/issues/24 but couldn’t get anything from it to work

What should I do?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6

github_iconTop GitHub Comments

4reactions
liuliangsircommented, May 11, 2021

@justrealmilk the following code snippet works with react-scripts@4.0.3

const WorkerPlugin = require('worker-plugin');

module.exports = {
  webpack: {
    configure: function(webpackConfig) {
      // some stuff

      return webpackConfig;
    },
    plugins: [
      new WorkerPlugin(),
    ],
  },
};```
0reactions
jrejaudcommented, Aug 7, 2022

Can you elaborate on your solution please? I’ve been following the guide at https://blog.johnnyreilly.com/2020/02/21/web-workers-comlink-typescript-and-react, however when my client tries to call the URL where the web worker’s file is supposed to live, there’s nothing there…

Read more comments on GitHub >

github_iconTop Results From Across the Web

using-craco-workers - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
craco-worker-loader - npm
Craco plugin for worker-loader. Latest version: 1.0.0, last published: 3 years ago. Start using craco-worker-loader in your project by ...
Read more >
How to use the customize-cra.addWebpackPlugin function in ...
To help you get started, we've selected a few customize-cra.addWebpackPlugin examples, based on popular ways it is used in public projects.
Read more >
How can I add support for web workers in a CRACO Webpack ...
Inside craco.config.js I add the plugin to my webpack object ... The larger portion of the library WorkerPlugin.prototype.apply does not ...
Read more >
React-refresh-webpack-plugin - npm.io
Check React-refresh-webpack-plugin 0.1.0 package - Last release 0.1.0 with MIT licence at our NPM packages aggregator and search engine.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found