diff --git a/packages/nuxt/src/core/builder.ts b/packages/nuxt/src/core/builder.ts index 99aa2a51f2..80b96abd8e 100644 --- a/packages/nuxt/src/core/builder.ts +++ b/packages/nuxt/src/core/builder.ts @@ -146,35 +146,36 @@ async function createParcelWatcher () { console.time('[nuxt] builder:parcel:watch') } const watcherPath = await tryResolveModule('@parcel/watcher', [nuxt.options.rootDir, ...nuxt.options.modulesDir]) - if (watcherPath) { - const { subscribe } = await import(pathToFileURL(watcherPath).href).then(interopDefault) as typeof import('@parcel/watcher') - for (const layer of nuxt.options._layers) { - if (!layer.config.srcDir) { continue } - const watcher = subscribe(layer.config.srcDir, (err, events) => { - if (err) { return } - for (const event of events) { - if (isIgnored(event.path)) { continue } - // TODO: consider moving to emit absolute path in 3.8 or 4.0 - nuxt.callHook('builder:watch', watchEvents[event.type], normalize(relative(nuxt.options.srcDir, event.path))) - } - }, { - ignore: [ - ...nuxt.options.ignore, - 'node_modules' - ] - }) - watcher.then((subscription) => { - if (nuxt.options.debug) { - // eslint-disable-next-line no-console - console.timeEnd('[nuxt] builder:parcel:watch') - } - nuxt.hook('close', () => subscription.unsubscribe()) - }) - } - return true + if (!watcherPath) { + logger.warn('Falling back to `chokidar-granular` as `@parcel/watcher` cannot be resolved in your project.') + return false } - logger.warn('Falling back to `chokidar-granular` as `@parcel/watcher` cannot be resolved in your project.') - return false + + const { subscribe } = await import(pathToFileURL(watcherPath).href).then(interopDefault) as typeof import('@parcel/watcher') + for (const layer of nuxt.options._layers) { + if (!layer.config.srcDir) { continue } + const watcher = subscribe(layer.config.srcDir, (err, events) => { + if (err) { return } + for (const event of events) { + if (isIgnored(event.path)) { continue } + // TODO: consider moving to emit absolute path in 3.8 or 4.0 + nuxt.callHook('builder:watch', watchEvents[event.type], normalize(relative(nuxt.options.srcDir, event.path))) + } + }, { + ignore: [ + ...nuxt.options.ignore, + 'node_modules' + ] + }) + watcher.then((subscription) => { + if (nuxt.options.debug) { + // eslint-disable-next-line no-console + console.timeEnd('[nuxt] builder:parcel:watch') + } + nuxt.hook('close', () => subscription.unsubscribe()) + }) + } + return true } async function bundle (nuxt: Nuxt) { diff --git a/packages/nuxt/src/core/schema.ts b/packages/nuxt/src/core/schema.ts index a20e256411..6e75198ae1 100644 --- a/packages/nuxt/src/core/schema.ts +++ b/packages/nuxt/src/core/schema.ts @@ -76,7 +76,7 @@ export default defineNuxtModule({ } return } - logger.warn('Falling back to `chokidar-granular` as `@parcel/watcher` cannot be resolved in your project.') + logger.warn('Falling back to `chokidar` as `@parcel/watcher` cannot be resolved in your project.') } const filesToWatch = await Promise.all(nuxt.options._layers.map(layer =>