Skip to content

Commit

Permalink
Add error for exporting when target is not server (vercel#6455)
Browse files Browse the repository at this point in the history
  • Loading branch information
dav-is authored Feb 26, 2019
1 parent 7dc50f3 commit 2fd397f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions errors/next-export-serverless.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Using `next export` with `target` not set to `server`

#### Why This Error Occurred

Next.js can only handle exporting when the `target` is set to `server` (this is the default value). A serverless build, for instance, has no handler for requests–this is usually implemented by a hosting provider.

#### Possible Ways to Fix It

Change `target` to `server`, run `next build`, then run `next export` again.
2 changes: 2 additions & 0 deletions packages/next/export/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export default async function (dir, options, configuration) {
const threads = options.threads || Math.max(cpus().length - 1, 1)
const distDir = join(dir, nextConfig.distDir)

if (nextConfig.target !== 'server') throw new Error('Cannot export when target is not server. https://err.sh/zeit/next.js/next-export-serverless')

log(`> using build directory: ${distDir}`)

if (!existsSync(distDir)) {
Expand Down

0 comments on commit 2fd397f

Please sign in to comment.