Skip to content

Commit c5d88a4

Browse files
fix: nextConfig was memoized too early (#264)
1 parent f3f597e commit c5d88a4

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

index.js

+16-15
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,24 @@ module.exports = {
2929
return failBuild('Could not find a package.json for this project')
3030
}
3131

32-
const nextConfig = await getNextConfig(utils.failBuild)
33-
await restoreCache({ cache: utils.cache, distDir: nextConfig.distDir })
34-
35-
if (await doesNotNeedPlugin({ netlifyConfig, packageJson, failBuild })) {
36-
return
32+
const pluginNotNeeded = await doesNotNeedPlugin({ netlifyConfig, packageJson, failBuild })
33+
34+
if (!pluginNotNeeded) {
35+
const nextConfigPath = await findUp('next.config.js')
36+
if (nextConfigPath === undefined) {
37+
// Create the next config file with target set to serverless by default
38+
const nextConfig = `
39+
module.exports = {
40+
target: 'serverless'
41+
}
42+
`
43+
await pWriteFile('next.config.js', nextConfig)
44+
}
3745
}
3846

39-
const nextConfigPath = await findUp('next.config.js')
40-
if (nextConfigPath === undefined) {
41-
// Create the next config file with target set to serverless by default
42-
const nextConfig = `
43-
module.exports = {
44-
target: 'serverless'
45-
}
46-
`
47-
await pWriteFile('next.config.js', nextConfig)
48-
}
47+
// Because we memoize nextConfig, we need to do this after the write file
48+
const nextConfig = await getNextConfig(utils.failBuild)
49+
await restoreCache({ cache: utils.cache, distDir: nextConfig.distDir })
4950
},
5051
async onBuild({
5152
netlifyConfig,

0 commit comments

Comments
 (0)