diff --git a/packages/nuxt3/src/core/builder.ts b/packages/nuxt3/src/core/builder.ts index d9a65e491d..0722660120 100644 --- a/packages/nuxt3/src/core/builder.ts +++ b/packages/nuxt3/src/core/builder.ts @@ -1,6 +1,6 @@ import chokidar from 'chokidar' import type { Nuxt } from '@nuxt/schema' -import { isIgnored, tryImportModule } from '@nuxt/kit' +import { importModule, isIgnored } from '@nuxt/kit' import { debounce } from 'perfect-debounce' import { createApp, generateApp as _generateApp } from './app' @@ -55,13 +55,21 @@ function watch (nuxt: Nuxt) { } async function bundle (nuxt: Nuxt) { - const { bundle } = typeof nuxt.options.builder === 'string' - ? await tryImportModule(nuxt.options.builder, { paths: nuxt.options.rootDir }) - : nuxt.options.builder try { + const { bundle } = typeof nuxt.options.builder === 'string' + ? await importModule(nuxt.options.builder, { paths: nuxt.options.rootDir }) + : nuxt.options.builder + return bundle(nuxt) } catch (error) { 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`.' + ].join('\n')) + } + throw error } }