From b565c38f4895354b6334f9ea042c95d9503e5dac Mon Sep 17 00:00:00 2001 From: mrazauskas <72159681+mrazauskas@users.noreply.github.com> Date: Thu, 12 Aug 2021 11:49:25 +0300 Subject: [PATCH] fix(generator): throw an error when Builder is missing (#9663) --- packages/generator/src/generator.js | 6 ++++++ packages/generator/test/generator.init.test.js | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/packages/generator/src/generator.js b/packages/generator/src/generator.js index 7147e7713b..caf459f124 100644 --- a/packages/generator/src/generator.js +++ b/packages/generator/src/generator.js @@ -84,6 +84,12 @@ export default class Generator { await this.nuxt.callHook('export:before', this) if (build) { + if (!this.builder) { + throw new Error( + `Could not generate. Make sure a Builder instance is passed to the constructor of Generator class or `getGenerator` function \ +or disable the build step: \`generate({ build: false })\``) + } + // Add flag to set process.static this.builder.forGenerate() diff --git a/packages/generator/test/generator.init.test.js b/packages/generator/test/generator.init.test.js index e2c977f616..8768633f6e 100644 --- a/packages/generator/test/generator.init.test.js +++ b/packages/generator/test/generator.init.test.js @@ -98,6 +98,13 @@ describe('generator: initialize', () => { expect(generator.initDist).not.toBeCalled() }) + test('should throw error when build is not disabled, but Builder instance is omitted', async () => { + const nuxt = createNuxt() + const generator = new Generator(nuxt) + + await expect(generator.initiate()).rejects.toThrow('Could not generate') + }) + test('should init routes with generate.routes and routes.json', async () => { const nuxt = createNuxt() nuxt.options = {