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.

ReferenceError: Worker is not defined & SecurityError: Failed to construct 'Worker': Script at 'webpack-internal:///./node_modules/wasm-imagemagick/dist/src/magick.js' cannot be accessed from origin 'http://localhost:3000'.

See original GitHub issue

Next.js gives the below error while importing the wasm-imagemagick package ReferenceError: Worker is not defined on the following line when I import that package in my component using import { execute} from 'wasm-imagemagick'

if (currentJavascriptURL.startsWith('http')) { 
    magickWorker = new Worker(window.URL.createObjectURL(new Blob([GenerateMagickWorkerText(magickWorkerUrl)]))); 
} else { 
    magickWorker = new Worker(magickWorkerUrl); 
}

I also tried to dynamically import the package on component load like below

useEffect(async () => {
    const Magick = await import("wasm-imagemagick");
}, [])

but then it gave me the below error

SecurityError: Failed to construct 'Worker': Script at 'webpack-internal:///./node_modules/wasm-imagemagick/dist/src/magick.js' cannot be accessed from origin 'http://localhost:3000'.

You can check the error by cloning this repo https://github.com/harshal247software/nextjsworkerissue.git. Just clone & run npm i & then npm run dev. I have taken the sample code from https://codesandbox.io/s/wasm-imagemagick-basic-demo-y00u2

I have also raised this bug to Next.js, Please check this conversation: https://github.com/vercel/next.js/issues/33217#issuecomment-1016513258

What should I do to make this package work with Next.js?

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
blipkcommented, Jan 30, 2022

There’s another issue open with the exact same error, and they report that it works if including it directly.

The issue is with webpack, or your configuration.

Anyway, not my repository, just trying to help.

1reaction
mix0000commented, Jan 28, 2022

I have similar issue: Failed to construct 'Worker': Script at 'webpack://l-video-editor/./node_modules/wasm-imagemagick/dist/src/magick.js' cannot be accessed from origin 'http://localhost:9000'.

Idk how but they get wrong URL for magick.js it can be access from _http://localhost:9000/magick.js_, but they taking it from webpack://l-video-editor/./node_modules/wasm-imagemagick/dist/src/magick.js

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting Failed to construct 'Worker' with JS worker file located ...
When I run my Django installation on my local machine, where I serve static files from the localhost there are no issues, which...
Read more >
When loading KMZs, I get an error when trying to access a ...
"Uncaught DOMException: Failed to construct 'Worker': Script at 'https://YYYYY.com/ThirdParty/Workers/inflate.js' cannot be accessed from origin ...
Read more >
Worker() - Web APIs - MDN Web Docs
The Worker() constructor creates a Worker object that executes the script at the specified URL. This script must obey the same-origin ...
Read more >
Failed to construct 'Worker': Access to the script at 'blob ...
Hi, I am getting an error while importing meshes while host the project in a particular server. I am not getting this in...
Read more >
issue with your HTTPS configuration - WordPress.org
Uncaught (in promise) DOMException: Failed to construct 'Worker': Script at ... cornerstone/assets/dist/js/worker.f241066.js' cannot be accessed from origin ...
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