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.

Could not load worker

See original GitHub issue

Problem

Couldn’t load worker, JSON syntax validation doesn’t work. I see Could not load worker warning in the browser console.

Also, I tried to import the json worker

import "ace-builds/src-noconflict/worker-json";

and got the error

TypeError: Cannot read property 'window' of undefined

Sample code to reproduce the issue

import React from "react";
import ReactDOM from "react-dom";
import AceEditor from "react-ace";

import "ace-builds/src-noconflict/ace";
import "ace-builds/src-noconflict/mode-json";
import "ace-builds/src-noconflict/theme-github";

let text =
  '{\n  "id": 0,\n  ' +
  '"script": """\n   function add(x, y) {\n      return x + y;\n   }\n   add(1, 2);\n   """' +
  ',\n   "descr": "add two numbers"\n}';

function App() {
  return (
    <div className="App">
      <h1>Code Editor Demo</h1>
      <AceEditor
        mode="json"
        theme="github"
        onChange={(value, stat) => {
          console.log("onChange", value, stat);
        }}
        value={text}
        name="UNIQUE_ID_OF_DIV"
        editorProps={{ $blockScrolling: true }}
      />
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

References

Codesandbox https://codesandbox.io/embed/ace-worker-3-vrr68

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:8
  • Comments:30 (1 by maintainers)

github_iconTop GitHub Comments

53reactions
nightwingcommented, Oct 17, 2019

You need to either include the webpack-resolver

import "ace-builds/webpack-resolver";

or configure the url for each mode separately

import jsonWorkerUrl from "file-loader!ace-builds/src-noconflict/worker-json";
ace.config.setModuleUrl("ace/mode/json_worker", jsonWorkerUrl)
import cssWorkerUrl from "file-loader!ace-builds/src-noconflict/worker-css";
ace.config.setModuleUrl("ace/mode/css_worker", cssWorkerUrl)

both methods require “file-loader”

also react-ace tries to load brace if ace is not already imported so ace-builds needs to be imported before react-ace.

import "ace-builds";
import AceEditor from "react-ace";
47reactions
sourovroycommented, Oct 27, 2019

setOptions={{ useWorker: false }}

works for me. Thanks @khoomeister

Read more comments on GitHub >

github_iconTop Results From Across the Web

Chrome Extension - Ace Editor worker fails to load
The reason it fails is due to a Content Security Policy error in the worker loader, which uses importScripts : importScripts('chrome-extension: ...
Read more >
Web worker fails to load in sandboxed iframe with Firefox 45
We see this behavior when using pdf.js to display PDF's inside a sandboxed iframe. Actual results: PDF.js fails to load the web worker...
Read more >
worker-loader - webpack - JS.ORG
Even downloads from the webpack-dev-server could be blocked. There are two workarounds: Firstly, you can inline the worker as a blob instead of...
Read more >
How to Solve the Chunk Load Error in JavaScript
If you observe that the files are not being served correctly or the URLs are incorrect, it should be straightforward to resolve this...
Read more >
Web Workers
I was trying to use web workers in a vue cli context. For some reasons, it would not load the worker file without...
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