fix(nuxt3): warn if builder can't be loaded (#3766)

This commit is contained in:
Daniel Roe 2022-03-18 12:57:05 +00:00 committed by GitHub
parent 2ad93eb34d
commit 6de6e42bb8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 4 deletions

View File

@ -1,6 +1,6 @@
import chokidar from 'chokidar' import chokidar from 'chokidar'
import type { Nuxt } from '@nuxt/schema' import type { Nuxt } from '@nuxt/schema'
import { isIgnored, tryImportModule } from '@nuxt/kit' import { importModule, isIgnored } from '@nuxt/kit'
import { debounce } from 'perfect-debounce' import { debounce } from 'perfect-debounce'
import { createApp, generateApp as _generateApp } from './app' import { createApp, generateApp as _generateApp } from './app'
@ -55,13 +55,21 @@ function watch (nuxt: Nuxt) {
} }
async function bundle (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 { try {
const { bundle } = typeof nuxt.options.builder === 'string'
? await importModule(nuxt.options.builder, { paths: nuxt.options.rootDir })
: nuxt.options.builder
return bundle(nuxt) return bundle(nuxt)
} catch (error) { } catch (error) {
await nuxt.callHook('build:error', 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 throw error
} }
} }