diff --git a/src/fs.ts b/src/fs.ts index dd5d6d24..1c807a4d 100644 --- a/src/fs.ts +++ b/src/fs.ts @@ -2,6 +2,7 @@ import fs from 'fs'; import util from 'util'; export default { + existsSync: fs.existsSync, readFile: util.promisify(fs.readFile), readFileSync: fs.readFileSync, watch: fs.watch, diff --git a/src/index.ts b/src/index.ts index d7f59ddf..1b7c229d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -45,6 +45,11 @@ export const open = async ( }; fs.watch(filepath, watcherOptions, async () => { + // When database file is being replaced, + // it could be removed for a fraction of a second. + if (!fs.existsSync(filepath)) { + return; + } const updateDatabase = await fs.readFile(filepath); reader.load(updateDatabase, opts); if (opts.watchForUpdatesHook) {