Skip to content

fix: warn if publish is "out" #978

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/helpers/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,17 @@ export const checkNextSiteHasBuilt = ({
failBuild: FailBuild
}): void | never => {
if (!existsSync(path.join(publish, 'BUILD_ID'))) {
const outWarning =
path.basename(publish) === 'out'
? `Your publish directory is set to "out", but in most cases it should be ".next".`
: `In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.`

return failBuild(outdent`
The directory "${path.relative(
process.cwd(),
publish,
)}" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
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.
)}" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
${outWarning}
If you are using "next export" then the Essential Next.js plugin should be removed. See https://ntl.fyi/remove-plugin for details.
`)
}
Expand Down
21 changes: 18 additions & 3 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,26 @@ describe('onBuild()', () => {
test("fails if BUILD_ID doesn't exist", async () => {
await moveNextDist()
await unlink(path.join(process.cwd(), '.next/BUILD_ID'))
const failBuild = jest.fn().mockImplementation(() => {
throw new Error('BUILD_ID does not exist')
const failBuild = jest.fn().mockImplementation((err) => {
throw new Error(err)
})
expect(() => plugin.onBuild({ ...defaultArgs, utils: { ...utils, build: { failBuild } } })).rejects.toThrow(
`In most cases it should be set to ".next", unless you have chosen a custom "distDir" in your Next config.`,
)
expect(failBuild).toHaveBeenCalled()
})

test("fails with helpful warning if BUILD_ID doesn't exist and publish is 'out'", async () => {
await moveNextDist()
await unlink(path.join(process.cwd(), '.next/BUILD_ID'))
const failBuild = jest.fn().mockImplementation((err) => {
throw new Error(err)
})
netlifyConfig.build.publish = path.resolve('out')

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

Expand Down