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.

bug: importScripts is not defined error inside web worker script

See original GitHub issue

I have a web worker worker.js that references a file e.g:

importScripts('file.js');

However Karma does not seem to like it:

INFO [karma]: Karma v0.12.37 server started at http://localhost:9877/
INFO [launcher]: Starting browser Chrome
INFO [Chrome 44.0.2403 (Linux 0.0.0)]: Connected on socket ZecIQTwPUPehOMzVhz-8 with id 85867718
Chrome 44.0.2403 (Linux 0.0.0) LOG: 'pre-main prep time: 2 ms'

Chrome 44.0.2403 (Linux 0.0.0) ERROR
    Uncaught ReferenceError: importScripts is not defined at /home/.../worker.js:1

importScripts is a standard API of the Worker global scope so it should not throw this error

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

4reactions
dignifiedquirecommented, Jul 27, 2015

This sounds like the script is not executed in a web worker, but rather in the general browser scope. Try opening the debug mode and look at what actually happens on execution. (This error is not coming from karma, it’s just relaying the error that Chrome sends)

0reactions
johnjbartoncommented, May 14, 2020

I don’t see anything in the stackoverflow post related to karma issues.

The karma test is just a web page and if your test configuration includes bad code then the page will fail with errors. The TroubleShooting page gives the recommended approach. http://karma-runner.github.io/5.0/intro/troubleshooting.html Basically you start your tests but the server does not exit. Then you use the browser debugger to find issues.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught ReferenceError: importScripts is not defined
This code needs to be inside a worker script. The worker itself is created via a new Worker object - see Getting Started...
Read more >
importscripts is not defined react - You.com | The AI Search ...
importScripts in Web Workers is undefined inside a React/Webpack environment ... bug: importScripts is not defined error inside web worker script .
Read more >
Using Web Workers - Web APIs - MDN Web Docs
Web Workers are a simple means for web content to run scripts in background threads. The worker thread can perform tasks without interfering ......
Read more >
Common Errors - RequireJS
... No define call for ...§ 6; Script error§ 7; No matching script interactive for . ... It is an error with the...
Read more >
Web Workers | Tizen Docs
To create and execute a Web worker: Create JavaScript code for a simple Boolean operation: · To create a subworker, use the importScripts()...
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