diff --git a/src/plugin.ts b/src/plugin.ts index 109b39b..9529aea 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -1,4 +1,4 @@ -import type { Scope, Config, FilesOption } from 'harper'; +import { flushDatabases, type Scope, type Config, type FilesOption } from 'harper'; import { createRequire } from 'node:module'; import { parse as urlParse } from 'node:url'; @@ -270,6 +270,11 @@ async function build(scope: Scope, config: NextPluginConfig, next: NextPackage) scope.logger.debug?.(`Building Next.js application at ${scope.directory}`); + // Next.js generates static pages using child processes and only a single process can open the + // RocksDB databases, so force Harper to start in read-only mode + process.env.HARPER_READONLY = 'true'; + await flushDatabases(); + // --expose-internals is set in Harper's worker execArgv but is not allowed in NODE_OPTIONS. // Next.js reads process.execArgv to forward flags to its own child workers via NODE_OPTIONS, // which causes Node to reject the build worker. Strip it before building and restore after.