Configure ace without file-loader #4815
Replies: 4 comments 2 replies
-
You need to either include the webpack-resolver import "ace-builds/webpack-resolver"; or configure the url import jsonWorkerUrl from "file-loader!ace-builds/src-noconflict/worker-json";
ace.config.setModuleUrl("ace/mode/json_worker", jsonWorkerUrl) both methods require "file-loader" |
Beta Was this translation helpful? Give feedback.
-
also there is another bug in react-ace, that causes error when react-ace is imported before ace. so you need to also rearrange imports like this: import "ace-builds/src-noconflict/ace";
import "ace-builds/src-noconflict/mode-json";
import "ace-builds/src-noconflict/theme-github";
import AceEditor from "react-ace"; |
Beta Was this translation helpful? Give feedback.
-
do you guys how to solve this as |
Beta Was this translation helpful? Give feedback.
-
With Webpack 5 you can import workers without any additional loaders (see documentation). You can just do this: const jsonWorkerUrl = new URL('ace-builds/src-noconflict/worker-json', import.meta.url);
config.setModuleUrl('ace/mode/json_worker', jsonWorkerUrl); With import AceEditor from "react-ace";
import { config } from "ace-builds";
...
const jsonWorkerUrl = new URL('ace-builds/src-noconflict/worker-json', import.meta.url);
config.setModuleUrl("ace/mode/json_worker", jsonWorkerUrl);
...
return <AceEditor ... /> |
Beta Was this translation helpful? Give feedback.
-
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
and got the error
Sample code to reproduce the issue
References
Codesandbox https://codesandbox.io/embed/ace-worker-3-vrr68
Beta Was this translation helpful? Give feedback.
All reactions