Repository: nuxt/nuxt
File: packages/nuxt/src/core/builder.ts (TypeScript)

Code before:
    await nuxt.callHook('build:error', error)

    if (error.toString().includes('Cannot find module \'@nuxt/webpack-builder\'')) {
      throw new Error('Could not load `@nuxt/webpack-builder`. You may need to add it to your project dependencies, following the steps in `https://github.com/nuxt/framework/pull/2812`.')
    }

    throw error
  }
}

async function loadBuilder (nuxt: Nuxt, builder: string): Promise<NuxtBuilder> {
  try {
    return await importModule(builder, { url: [directoryToURL(nuxt.options.rootDir), new URL(import.meta.url)] })
  } catch (err) {
    throw new Error(`Loading \`${builder}\` builder failed. You can read more about the nuxt \`builder\` option at: \`https://nuxt.com/docs/4.x/api/nuxt-config#builder\``, { cause: err })
  }
}

function resolvePathsToWatch (nuxt: Nuxt, opts: { parentDirectories?: boolean } = {}): Set<string> {
  const pathsToWatch = new Set<string>()
  for (const dirs of getLayerDirectories(nuxt)) {
    if (!isIgnored(dirs.app)) {
      pathsToWatch.add(dirs.app)
    }
    // Only add server if it's not inside app (avoid double-watching)
    if (!isIgnored(dirs.server) && !dirs.server.includes(dirs.app.replace(/\/?$/, '/'))) {
      pathsToWatch.add(dirs.server)
    }
  }
  for (const pattern of nuxt.options.watch) {
    if (typeof pattern !== 'string') { continue }
    const path = opts?.parentDirectories
      ? join(dirname(resolve(nuxt.options.srcDir, pattern)), '')
      : resolve(nuxt.options.srcDir, pattern)
    let shouldAdd = true
    for (const w of [...pathsToWatch]) {
      if (w.startsWith(path)) {
        pathsToWatch.delete(w)
      }
      if (path.startsWith(w)) {
        shouldAdd = false
      }
    }
    if (shouldAdd) {
      pathsToWatch.add(path)
    }
  }
  return pathsToWatch
}


Review comment (suggestion):
```suggestion
    if (!isIgnored(dirs.server) && !dirs.server.startsWith(dirs.app.replace(/\/?$/, '/'))) {
```

Code after:
    await nuxt.callHook('build:error', error)

    if (error.toString().includes('Cannot find module \'@nuxt/webpack-builder\'')) {
      throw new Error('Could not load `@nuxt/webpack-builder`. You may need to add it to your project dependencies, following the steps in `https://github.com/nuxt/framework/pull/2812`.')
    }

    throw error
  }
}

async function loadBuilder (nuxt: Nuxt, builder: string): Promise<NuxtBuilder> {
  try {
    return await importModule(builder, { url: [directoryToURL(nuxt.options.rootDir), new URL(import.meta.url)] })
  } catch (err) {
    throw new Error(`Loading \`${builder}\` builder failed. You can read more about the nuxt \`builder\` option at: \`https://nuxt.com/docs/4.x/api/nuxt-config#builder\``, { cause: err })
  }
}

function resolvePathsToWatch (nuxt: Nuxt, opts: { parentDirectories?: boolean } = {}): Set<string> {
  const pathsToWatch = new Set<string>()
  for (const dirs of getLayerDirectories(nuxt)) {
    if (!isIgnored(dirs.app)) {
      pathsToWatch.add(dirs.app)
    }
    // Only add server if it's not inside app (avoid double-watching)
    if (!isIgnored(dirs.server) && !dirs.server.startsWith(dirs.app.replace(/\/?$/, '/'))) {
      pathsToWatch.add(dirs.server)
    }
  }
  for (const pattern of nuxt.options.watch) {
    if (typeof pattern !== 'string') { continue }
    const path = opts?.parentDirectories
      ? join(dirname(resolve(nuxt.options.srcDir, pattern)), '')
      : resolve(nuxt.options.srcDir, pattern)
    let shouldAdd = true
    for (const w of [...pathsToWatch]) {
      if (w.startsWith(path)) {
        pathsToWatch.delete(w)
      }
      if (path.startsWith(w)) {
        shouldAdd = false
      }
    }
    if (shouldAdd) {
      pathsToWatch.add(path)
    }
  }
  return pathsToWatch
}