Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker Using worker in Vue and Typescript, Unable to use web worker ??? #10991

Closed
wangzhiyao66 opened this issue Jan 8, 2020 · 5 comments
Closed

Comments

@wangzhiyao66
Copy link

@wangzhiyao66 wangzhiyao66 commented Jan 8, 2020

Version

2.6.10

Reproduction link

https://github.com/wangzhiyao66/my-worker.git

Steps to reproduce

An error occurred while using the following code in the script

let worker = new Worker('../../static/webworker.js');

What is expected?

Normal use web worker

What is actually happening?

Uncaught SyntaxError: Unexpected token '<'
Cause unexpected end


I need your help to solve this problem. Thank you very much

@LinusBorg

This comment has been minimized.

Copy link
Member

@LinusBorg LinusBorg commented Jan 8, 2020

The path that you pass to the Worker() function should be the absolute path to the file on the server, not a local path in you src folder. (so preusamably: '/static/webworker.js'

Because of the wrong path, the HTTP server can't find the file and replies with a 404 error page - which starts with "<" (as in <html>)

Problem is not related to Vue.

@LinusBorg LinusBorg closed this Jan 8, 2020
@wangzhiyao66

This comment has been minimized.

Copy link
Author

@wangzhiyao66 wangzhiyao66 commented Jan 8, 2020

@wangzhiyao66

This comment has been minimized.

Copy link
Author

@wangzhiyao66 wangzhiyao66 commented Jan 8, 2020

@LinusBorg

This comment has been minimized.

Copy link
Member

@LinusBorg LinusBorg commented Jan 8, 2020

You can create workers "inline", without a script loaded from the server. But that is something for which you don't need specific support in your frontend framework of choice.

Angular, being a big framework incorporating lots of stuff like its own http fetch solution etc, may have this built-in - Vue doesn't.

if you have a system set up with Vue CLI (or webpack in general), you might be able to achieve your desired result by adding this loader:

https://github.com/webpack-contrib/worker-loader

or a similar solution.

@wangzhiyao66

This comment has been minimized.

Copy link
Author

@wangzhiyao66 wangzhiyao66 commented Jan 9, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.