ajaxorg/ace · warning
Could not load worker
Error message
Could not load worker
What it means
config.warn('Could not load worker', e) fires when $startWorker's call to mode.createWorker(session) throws — i.e., the mode's background worker (syntax checker/highlighter worker) failed to spawn. The session continues in degraded mode with $worker = null; this is a logged warning, not a thrown exception.
Source
Thrown at src/edit_session.js:1051
this.$options.wrapMethod.set.call(this, this.$wrapMethod);
this.$setFolding(mode.foldingRules);
this.bgTokenizer.start(0);
this._emit("changeMode", {oldMode: oldMode, mode: mode});
}
}
$stopWorker() {
if (this.$worker) {
this.$worker.terminate();
this.$worker = null;
}
}
$startWorker() {
try {
this.$worker = this.$mode.createWorker(this);
} catch (e) {
config.warn("Could not load worker", e);
this.$worker = null;
}
}
/**
* Returns the current text mode.
* @returns {TextMode} The current text mode
**/
getMode() {
return this.$mode;
}
/**
* This function sets the scroll top value. It also emits the `'changeScrollTop'` event.
* @param {Number} scrollTop The new scroll top value
**/
setScrollTop(scrollTop) {
// TODO: should we force integer lineheight instead? scrollTop = Math.round(scrollTop);View on GitHub (pinned to 2c1eddc392)
Solutions
- Include the full ace worker files (e.g., worker-javascript.js) alongside the core, matching your ace version
- If self-hosting, set ace.config.set('workerPath', '/path/to/ace/build') to the directory containing worker scripts
- Check the second argument of the warning in console for the underlying error (404, CSP, SecurityError)
- Use a single-file bundle like ace.js from the build which inlines workers, or disable the worker with mode-specific options if linting isn't needed
Example fix
// before
ace.config.set('basePath', '/js/ace'); // workers missing from /js/ace
// after
ace.config.set('basePath', '/js/ace');
ace.config.set('workerPath', '/js/ace'); // dir containing worker-javascript.js etc. Defensive patterns
Strategy: fallback
Validate before calling
// ensure workers are reachable before creating the editor
fetch(ace.config.get('workerPath') + '/worker-javascript.js', { method: 'HEAD' })
.catch(function() { console.warn('workers unavailable; running without lint worker'); }); Try / catch
// ace catches internally and continues ($worker = null); on your side:
editor.session.on('changeAnnotation', function() {
if (editor.session.$worker === null) console.info('no worker; annotations limited');
}); Prevention
- Ship the full ace build directory including all worker-*.js files
- Set ace.config.set('workerPath', ...) when workers aren't adjacent to the core
- Add CSP worker-src 'self' (or blob:) if you use a strict CSP
- Use the single-file ace build that inlines workers when deploy layout is uncertain
- Note file:// origins can block workers — serve over http
When it happens
Trigger: Loading Ace from a CDN/cross-origin origin where worker scripts can't be fetched, a missing worker JS file (e.g., worker-javascript.js 404), mismatched ace versions between main lib and workers, or restrictive CSP without worker-src.
Common situations: Self-hosting ace with an incomplete copy of the lib directory; bundlers that fail to emit the worker chunk; file:// or sandboxed iframes blocking Web Workers; old mode files against a newer ace core.
Related errors
AI-assisted analysis of ajaxorg/ace@2c1eddc392 (2026-08-30).
Data as JSON: /api/errors/fd3b1574f3cd4362.
Report an issue: GitHub.