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 cannot be imported from different origin. #613

Closed
ppascualv opened this issue Jul 23, 2020 · 6 comments · Fixed by #756
Closed

Worker cannot be imported from different origin. #613

ppascualv opened this issue Jul 23, 2020 · 6 comments · Fixed by #756
Labels
question Further information is requested

Comments

@ppascualv
Copy link

ppascualv commented Jul 23, 2020

What are you trying to achieve? Please describe.

I have a web page under domain.com that uses a CDN for the JS files, the problem is that the origin is different then when I tri to import the worker Chrome says:
Uncaught DOMException: Failed to construct 'Worker' 'https://cdn.com' cannot be accessed from origin 'https:domain.com' and CORS are well configured.

I'm using this import
import { Document } from 'react-pdf/dist/esm/entry.webpack';

This is not happening in Firefox

Describe solutions you've tried

I tried to use a subdomain for the CDN like cdn.domain.com but not working neither.

@wojtekmaj wojtekmaj added help wanted Extra attention is needed question Further information is requested labels Jul 27, 2020
@vijayapalponram
Copy link

Am also facing the same kind of error while loading the worker from different origin.
image

@wojtekmaj
Copy link
Owner

Well, you shouldn't do that. Loading scripts from different origins is usually a bad idea.

@wojtekmaj wojtekmaj removed the help wanted Extra attention is needed label Nov 1, 2020
@vijayapalponram
Copy link

As per Micro Front end architecture, i can load my one of the module script from another origin.
https://single-spa.js.org/

@simy307
Copy link

simy307 commented Nov 16, 2020

Same problem here. We are using the new Module Federation in webpack 5 and we have the same issue.

@wojtekmaj
Copy link
Owner

Please kindly check React-PDF v5.3.0-beta.2, in which improvements regarding loading PDF.js worker were made.

These changes should result in 10-15 seconds faster Webpack builds, as well as you should be able to use Webpack entry file in Create-React-App, without the need of using external CDN for hosting worker.

Let me know what you think in #748!

@sbodi10
Copy link

sbodi10 commented Apr 14, 2021

What are you trying to achieve? Please describe.

I have a web page under domain.com that uses a CDN for the JS files, the problem is that the origin is different then when I tri to import the worker Chrome says:
Uncaught DOMException: Failed to construct 'Worker' 'https://cdn.com' cannot be accessed from origin 'https:domain.com' and CORS are well configured.

I'm using this import
import { Document } from 'react-pdf/dist/esm/entry.webpack';

This is not happening in Firefox

Describe solutions you've tried

I tried to use a subdomain for the CDN like cdn.domain.com but not working neither.

Updating version to v5.3.0-beta.2 worked for me! 🎉
Thanks @wojtekmaj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants