Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[@nuxt/content 3.16.1] `UNIQUE constraint failed: _development_cache.id` unhandled rejections: `insertDevelopmentCache` doesn't await the delete

Open Beginner friendly
#3,865 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
76/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
node.js, sqlite, typescript
Domain
backend, databases

Research direction

Start by locating insertDevelopmentCache and deleteDevelopmentCache in the package source corresponding to dist/module.mjs around the reported line 361; trace their callers in the build loop and watcher. Reproduce with two builds after changing a Markdown file, then verify the delete completes before insertion and that callers handle the promise. Done when cache refreshes without unhandled rejections or missing rows.

Written by the indexing model from the issue text.

Description

Environment

  • OS: Windows 11
  • Node: 24.21.0
  • Package manager: npm 11.19.0
  • Framework: Nuxt 4.5.2
  • Affected package: @nuxt/content 3.16.1 (same code in 3.15.2)
  • db0: 0.4.1 (nested under @nuxt/content)
  • better-sqlite3: 13.0.3 (local cache database)

Steps to reproduce

  1. Build a project with markdown collections once, so that _development_cache gets populated:
npx nuxt build
  1. Change some markdown files (or upgrade @nuxt/content, so that the collection/config hash changes) and build again:
npx nuxt build

Describe the bug

When a cached entry exists but its checksum no longer matches, the build logs one UNIQUE constraint failed: _development_cache.id unhandled rejection per changed file. The build completes, but the cache rows for those files end up missing and they are parsed again on the next build, which then runs clean.

Root cause: insertDevelopmentCache calls deleteDevelopmentCache(id) without await, and deleteDevelopmentCache doesn't await its own run() either:

const insertDevelopmentCache = async (id, value, checksum) => {
  deleteDevelopmentCache(id);
  const insert = generateCollectionInsert(cacheCollection, { id, value, checksum });
  for (const query of insert.queries) {
    await db.exec(query);
  }
};
const deleteDevelopmentCache = async (id) => {
  db.prepare(`DELETE FROM _development_cache WHERE id = ?`).run(id);
};

With the db0 better-sqlite3 connector, prepare() returns a wrapper whose run() first awaits getDB() and then the prepared statement (two awaits), while exec() awaits getDB() only once. So the INSERT executes before the DELETE and hits the existing primary key. The callers (db.insertDevelopmentCache(...) in the build loop and in the watcher) don't await or catch it either, so the rejection is unhandled.

Suggested fix:

const insertDevelopmentCache = async (id, value, checksum) => {
  await deleteDevelopmentCache(id);
  // ...
};
const deleteDevelopmentCache = async (id) => {
  await db.prepare(`DELETE FROM _development_cache WHERE id = ?`).run(id);
};

(or a single INSERT OR REPLACE).

Logs

 ERROR  [unhandledRejection] UNIQUE constraint failed: _development_cache.id

    at Database.exec (node_modules\better-sqlite3\lib\methods\wrappers.js:9:14)
    at Object.exec (/C:/projects/my-app/node_modules/@nuxt/content/node_modules/db0/dist/connectors/better-sqlite3.mjs:22:40)
    at async Object.insertDevelopmentCache (/C:/projects/my-app/node_modules/@nuxt/content/dist/module.mjs:361:7)

Additional context

The error was printed 7 times in a single build (7 changed files) and disappeared on the following build. It doesn't break the output, but it is noisy and it silently drops the cache entries it was supposed to refresh. The same pattern is present in @nuxt/content 3.15.2.

Dominant language
TypeScript
Stars
3.7k
Forks
746
Avg merge
1d 10h
Merged PRs (30d)
10

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from nuxt/content

All issues in nuxt/content

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.