From a569e61481284dc04c77f31f337e603024e616ae Mon Sep 17 00:00:00 2001 From: Lindsay Levine Date: Mon, 3 May 2021 14:03:35 -0400 Subject: [PATCH] fix: nextConfig was memoized too early --- index.js | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 4a5a1fb6b9..6c52b2bcd2 100644 --- a/index.js +++ b/index.js @@ -29,23 +29,24 @@ module.exports = { return failBuild('Could not find a package.json for this project') } - const nextConfig = await getNextConfig(utils.failBuild) - await restoreCache({ cache: utils.cache, distDir: nextConfig.distDir }) - - if (await doesNotNeedPlugin({ netlifyConfig, packageJson, failBuild })) { - return + const pluginNotNeeded = await doesNotNeedPlugin({ netlifyConfig, packageJson, failBuild }) + + if (!pluginNotNeeded) { + const nextConfigPath = await findUp('next.config.js') + if (nextConfigPath === undefined) { + // Create the next config file with target set to serverless by default + const nextConfig = ` + module.exports = { + target: 'serverless' + } + ` + await pWriteFile('next.config.js', nextConfig) + } } - const nextConfigPath = await findUp('next.config.js') - if (nextConfigPath === undefined) { - // Create the next config file with target set to serverless by default - const nextConfig = ` - module.exports = { - target: 'serverless' - } - ` - await pWriteFile('next.config.js', nextConfig) - } + // Because we memoize nextConfig, we need to do this after the write file + const nextConfig = await getNextConfig(utils.failBuild) + await restoreCache({ cache: utils.cache, distDir: nextConfig.distDir }) }, async onBuild({ netlifyConfig,