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
Could not load worker #725
Comments
I'm experiencing something similar for CSS, getting the following error in browser console:
When attempting to import worker directly
My build failed with:
|
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"; |
@nightwing that works but importing import AceEditor from 'react-ace';
import 'ace-builds/webpack-resolver';
// then the mode, theme & extension
import 'ace-builds/src-noconflict/mode-json';
import 'ace-builds/src-noconflict/theme-tomorrow_night';
import 'ace-builds/src-noconflict/ext-searchbox'; But I couldn't get it to work with my tests. The TypeError: Cannot read property 'setModuleUrl' of undefined I'm guessing I need mock ace with something like global.ace = require('ace-builds/src-min-noconflict/ace'); |
Did anyone get this working with create-react-app? Mine gets stuck compiling forever if I add:
|
I fixed by adding |
@khoomeister that got rid of all the warnings, but did your performance get noticeably worse (that could just be my implementation)? (thanks for the tip btw!) |
works for me. Thanks @khoomeister |
also still having this issue. |
I'm using a create-react-app project. The only thing I needed to do was to add this in my App.tsx:
Setting useWorker to false disables syntax checking at least, maybe other things, so I didn't want to use that. I don't know yet if this is good enough to make it work with tests as per arjunu's comment above. |
Adding webpack-resolver to my create-react-app project leads to a huge increase in compile time, and adds hundreds of files to the build directory - I assume one for each module in ace-builds that it configures. Configuring the url for just the modules that I need works fine, though. This seems like it's an issue with either react-scripts or ace-builds, not react-ace. |
So far I am happy with I was attempting to upgrade to version 8 but I failed due to issues with I am using I could not get worker to load, and the following errors were displayed in the console:
Disabling the worker is not an option for me. I tried adding the webpack-resolver using I also attempted to add it manually using the It seems that this issue is related to #733 #755 and ajaxorg/ace#4770 |
@mattjstar I got it working with:
So import See @arjunu answer above. |
I added the last 3 lines to add javascript-worker :
You can copy/paste the file worker-javascript.js in your local environment if you don't want to be dependant of cdn.jsdelivr.net. |
This works perfectly. Define worker URL before using any mode or theme
also no need to set: |
What if i want to have a custom worker that is not in the |
I leave the full
|
@jan-osch so if I want to use my "customWorker.js" for example, i've to set |
If you want to use the workarounds in Typescript you'll need to do this to set ace config:
|
I added the following test to Webpack
then I was able to import as following
|
I'm importing as suggested by @pranavwani but now am running into the error I believe that the issue is that since |
you can also do that without modify webpack config
|
They were causing issues (see securingsincity/react-ace#725) and were not necessary anyways.
do you guys how to solve this as |
What is the status of this issue? Although importing |
The following seems to have worked for me. The key is the order of imports and the last three lines (including the comment!) I got it from this reply.
|
None of these suggestions are working for me. I am getting the same When I use:
I get the following error: After comparing
Turns into:
I believe this is causing me and the OPs issue. Any idea why these files would be transformed like this? |
Adding |
I had trouble getting webpack-resolver to play nicely with Jest and couldn't figure out the magic I was able to work around this in Webpack v5 by using an Asset Module targeting the worker* files in ace-build: // webpack.config.js
module: {
rules: [
{
test: /worker-.*\.js/,
include: [/node_modules\/ace-build/],
type: 'asset/resource',
}
]
} // editor.js
import ace from 'ace-builds/src-noconflict/ace';
import 'ace-builds/src-noconflict/mode-json';
import jsonWorker from 'ace-builds/src-noconflict/worker-json';
ace.config.setModuleUrl('ace/mode/json_worker', jsonWorker); |
For those of you using Vite, I was able to get it working using Explicit URL Imports (appending import ace from 'ace-builds/src-noconflict/ace';
import jsonWorkerUrl from 'ace-builds/src-noconflict/worker-json?url';
ace.config.setModuleUrl('ace/mode/json_worker', jsonWorkerUrl);
// ... mode and theme imports here |
import ace from 'ace-builds/src-min-noconflict/ace';
import 'ace-builds/webpack-resolver'; This solution works for me, it solves all my import problems, include worker execute problem. |
For those searching how to implement workers now, when webpack config: rules: [
{
test: /ace-builds.*\/worker-.*$/,
type: "asset/resource"
},
], component: import AceEditor from "react-ace";
import { config } from "ace-builds";
import "ace-builds/src-noconflict/mode-javascript";
import "ace-builds/src-noconflict/theme-github";
import "ace-builds/src-noconflict/ext-language_tools";
import jsWorkerUrl from "ace-builds/src-noconflict/worker-javascript";
config.setModuleUrl("ace/mode/javascript_worker", jsWorkerUrl); To fix the typescript "no module declaration" error, just add the declare module "ace-builds/src-noconflict/worker-javascript"; |
@Cactusx09 thank you!!! For those who don't know how to add webpack configs to a nextjs project, here's my snippet:
|
Thanks This is also the solution if you don't use |
Yes, it works also for me. |
if you use vite, you can ... import { viteStaticCopy } from 'vite-plugin-static-copy'
export default defineConfig(() => {
plugins: [
viteStaticCopy({
targets: [
{
src: [
'node_modules/ace-builds/src-min-noconflict/ace.js',
'node_modules/ace-builds/src-min-noconflict/mode-json.js',
'node_modules/ace-builds/src-min-noconflict/worker-json.js'
],
dest: 'node_modules/ace-builds/src-min-noconflict/'
}
]
})],
}) |
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
The text was updated successfully, but these errors were encountered: