sveltejs/kit · error
Cannot add tasks to a queue that has ended
Error message
Cannot add tasks to a queue that has ended
What it means
SvelteKit's internal task queue (used during prerendering/build) exposes add() for scheduling work. Once q.end() is called the queue is closed; adding more tasks afterwards throws this error. It indicates scheduling work after the build phase has been finalized.
Source
Thrown at packages/kit/src/core/postbuild/queue.js:52
.then(task.fulfil, (err) => {
task.reject(err);
reject(err);
})
.then(() => {
current -= 1;
dequeue();
});
} else if (current === 0) {
closed = true;
resolve();
}
}
}
return {
/** @param {() => any} fn */
add: (fn) => {
if (closed) throw new Error('Cannot add tasks to a queue that has ended');
const promise = new Promise((fulfil, reject) => {
tasks.push({ fn, fulfil, reject });
});
promise.catch(() => {});
dequeue();
return promise;
},
done: () => {
if (current === 0) {
closed = true;
resolve();
}
return promise;
}View on GitHub (pinned to 03f1687fe6)
Solutions
- Ensure all q.add() calls complete before invoking q.end() — await outstanding tasks first
- Reorder code so end() is only called after every producer has finished enqueueing
- Track closed state in your wrapper and skip/queue-later instead of calling add after end
- If triggered by a plugin, update the plugin to a version compatible with your @sveltejs/kit build pipeline
Example fix
// before await Promise.all(items.map((i) => q.add(() => render(i)))); q.end(); stragglers.forEach((i) => q.add(() => render(i))); // throws // after for (const i of items) await q.add(() => render(i)); for (const i of stragglers) await q.add(() => render(i)); q.end();
Defensive patterns
Strategy: try-catch
Validate before calling
function safeAdd(q, closed, fn) {
if (closed) return Promise.resolve();
return q.add(fn);
} Try / catch
try {
await q.add(task);
} catch (e) {
if (String(e.message).includes('queue that has ended')) {
console.warn('Queue closed; run task directly or reschedule');
return task();
}
throw e;
} Prevention
- Await every q.add() promise before calling q.end()
- Never enqueue from callbacks that can resolve after teardown
- Keep one owner of the queue lifecycle in your build code
When it happens
Trigger: Calling q.add(fn) after q.end() on the queue returned by create_queue — in practice, code or a plugin hook that enqueues prerender/render tasks after the prerender step completes.
Common situations: Custom build tooling integrating with Kit internals; async callbacks resolving after q.end() and then trying to add work; misordered lifecycle code in postbuild scripts.
Related errors
- ${message}. Since you're using @sveltejs/adapter-auto, Svelt
- adapter-bun requires running the SvelteKit build with Bun. U
- ${log.message ?? String(log)}
- Cloudflare Pages' _routes.json should be configured from the
- @sveltejs/adapter-netlify >=2.x (possibly installed through
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/5926a814924eb314.
Report an issue: GitHub.