Skip to content

Commit 396f0f8

Browse files
fix: warn if publish is "out" (#978)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 37ef6f8 commit 396f0f8

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/helpers/verification.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,17 @@ export const checkNextSiteHasBuilt = ({
6161
failBuild: FailBuild
6262
}): void | never => {
6363
if (!existsSync(path.join(publish, 'BUILD_ID'))) {
64+
const outWarning =
65+
path.basename(publish) === 'out'
66+
? `Your publish directory is set to "out", but in most cases it should be ".next".`
67+
: `In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.`
68+
6469
return failBuild(outdent`
6570
The directory "${path.relative(
6671
process.cwd(),
6772
publish,
68-
)}" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
69-
In most cases it should be set to the site's ".next" directory path, unless you have chosen a custom "distDir" in your Next config.
73+
)}" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
74+
${outWarning}
7075
If you are using "next export" then the Essential Next.js plugin should be removed. See https://ntl.fyi/remove-plugin for details.
7176
`)
7277
}

test/index.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,26 @@ describe('onBuild()', () => {
208208
test("fails if BUILD_ID doesn't exist", async () => {
209209
await moveNextDist()
210210
await unlink(path.join(process.cwd(), '.next/BUILD_ID'))
211-
const failBuild = jest.fn().mockImplementation(() => {
212-
throw new Error('BUILD_ID does not exist')
211+
const failBuild = jest.fn().mockImplementation((err) => {
212+
throw new Error(err)
213213
})
214+
expect(() => plugin.onBuild({ ...defaultArgs, utils: { ...utils, build: { failBuild } } })).rejects.toThrow(
215+
`In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.`,
216+
)
217+
expect(failBuild).toHaveBeenCalled()
218+
})
219+
220+
test("fails with helpful warning if BUILD_ID doesn't exist and publish is 'out'", async () => {
221+
await moveNextDist()
222+
await unlink(path.join(process.cwd(), '.next/BUILD_ID'))
223+
const failBuild = jest.fn().mockImplementation((err) => {
224+
throw new Error(err)
225+
})
226+
netlifyConfig.build.publish = path.resolve('out')
214227

215-
expect(() => plugin.onBuild({ ...defaultArgs, utils: { ...utils, build: { failBuild } } })).rejects.toThrow()
228+
expect(() => plugin.onBuild({ ...defaultArgs, utils: { ...utils, build: { failBuild } } })).rejects.toThrow(
229+
`Your publish directory is set to "out", but in most cases it should be ".next".`,
230+
)
216231
expect(failBuild).toHaveBeenCalled()
217232
})
218233

0 commit comments

Comments
 (0)