bug: importScripts is not defined error inside web worker script
See original GitHub issueI 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:
- Created 8 years ago
- Comments:10 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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)
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.