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.

No support for web worker when using Typescript and Webpack 5?

See original GitHub issue

Describe the bug

Webpack 5 has deprecated ‘worker-loader’

When using the suggested webpack 5 compat loader API such as

const worker = new Worker(new URL('./test.worker.ts', import.meta.url));  
worker.postMessage("test");

The CRA loaders @pmmmwh/react-refresh-webpack-plugin and babel-loader fails, and instead it returns with error

‘You may need an additional loader to handle the result of these loaders.’

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:5
  • Comments:8

github_iconTop GitHub Comments

3reactions
cmdcolincommented, Feb 21, 2022

thanks for noting this @ninichki I did not try using the test suite but I also get the same error. This may be related to jest and esm module support, not sure what the fix is though

2reactions
cmdcolincommented, Jan 14, 2022

I found that I could use a web worker with webpack 5 and create-react-app v5 with the deep thought example here https://webpack.js.org/guides/web-workers/

bare bones repo example https://github.com/cmdcolin/cra-webpack5-web-worker-example

@toeryn you mention using react-scripts 4 but this thread is about webpack 5

Read more comments on GitHub >

github_iconTop Results From Across the Web

Web Workers written in Typescript in Webpack 5: SyntaxError
Webpack 5 documentation mentions that worker-loader is not needed anymore, and it seems easy for javascript files. However, I am using ...
Read more >
Web Workers | webpack - JS.ORG
Web Workers. As of webpack 5, you can use Web Workers without worker-loader . ... Worker in CommonJS syntax is not supported by...
Read more >
Loading web workers using Webpack 5 · mmazzarolo.com
As of today, there's not much documentation around webpack 5's web worker supports. It indeed works pretty well for the most common use-cases ......
Read more >
How to bundle WebWorker coded with TypeScript in npm ...
To use Web Workers in webpack 5, ... (The worker-loader is deprecated in webpack5, but I've decided that it's not an option for...
Read more >
Web workers, React, and TypeScript - LogRocket Blog
Web workers are a means for web browsers to run scripts in the background without interfering with the UI. If set up correctly,...
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