You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have followed the instructions in this doc, to resolve the issue with worker in webpack. But I am getting this error
monaco-editor.tsx:217 Uncaught (in promise) SecurityError: Failed to construct 'Worker':
Script at 'https://localhost:8093/424f6725c1d67c553d1e.js' cannot be accessed from origin
'https://us.mysite.com'.
I am running it in a single page application. I was wondering if this is a known issue and there is any preferred way to solve it?
I was able to solve the "cannot be accessed from origin" error, by using blob (I don't know if its the right way to do it). But textmate worker is throwing an error "document is not defined"
Here is how I am setting the workers:
constcreateWorker=async(workerUrl: string,workerName: string)=>{// const workerUrl = new URL(file, import.meta.url).href;constresponse=awaitfetch(workerUrl);if(!response.ok){thrownewError(`Failed to fetch worker: ${response.statusText}`);}constworkerCode=awaitresponse.text();constblob=newBlob([workerCode],{type: 'application/javascript'});constblobUrl=URL.createObjectURL(blob);constworker=newWorker(blobUrl,{type: 'module',name: workerName,});returnworker;};exportconstdefineDefaultWorkerLoaders: ()=>Record<string,WorkerLoader>=()=>{constdefaultTextEditorWorker=()=>createWorker(newURL('../../../examples/src/assets/monaco-workers/editor.js',import.meta.url).href,'TextEditorWorker');constdefaultTextMateWorker=()=>createWorker(newURL('../../../examples/src/assets/monaco-workers/textmate.js',import.meta.url).href,'TextMateWorker');return{// if you import monaco api as 'monaco-editor': monaco-editor/esm/vs/editor/editor.worker.jsTextEditorWorker: defaultTextEditorWorker,TextMateWorker: defaultTextMateWorker,// these are other possible workers not configured by defaultOutputLinkDetectionWorker: undefined,LanguageDetectionWorker: undefined,NotebookEditorWorker: undefined,LocalFileSearchWorker: undefined};};exportconstconfigureDefaultWorkerFactory=(logger?: Logger)=>{useWorkerFactory({workerLoaders: defineDefaultWorkerLoaders(),
logger
});};
@dhrubomoy btw, did you compare your webpack config with our verification example? I don't see this problem there. But I see that the Textmate highlighting is only working after I interacted with the editor.
You can take a look at the file that gets generated by webpack here. Below is the line where the error occurs. I have no idea where that line is coming from
If I change the textmate entry file to following I don't see the error, though I still see thedocument.getElementsByTagName("script") line in the webpacked file
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I have followed the instructions in this doc, to resolve the issue with worker in webpack. But I am getting this error
I am running it in a single page application. I was wondering if this is a known issue and there is any preferred way to solve it?
Thanks in advance.
All reactions