Skip to content

Commit

Permalink
Throw Error When Running next start on Serverless Build (vercel#6166)
Browse files Browse the repository at this point in the history
  • Loading branch information
dav-is authored and timneutkens committed Jan 29, 2019
1 parent 1475491 commit 8b24103
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 9 additions & 0 deletions errors/next-start-serverless.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Using `next start` with `target` not set to `server`

#### Why This Error Occurred

Next.js can only handle running a server 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

Use a different handler than `next start` when testing a serverless **production** build, otherwise just use `next dev`.
4 changes: 3 additions & 1 deletion packages/next-server/server/next-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export default class Server {

// Only serverRuntimeConfig needs the default
// publicRuntimeConfig gets it's default in client/index.js
const {serverRuntimeConfig = {}, publicRuntimeConfig, assetPrefix, generateEtags} = this.nextConfig
const {serverRuntimeConfig = {}, publicRuntimeConfig, assetPrefix, generateEtags, target} = this.nextConfig

if (process.env.NODE_ENV === 'production' && target !== 'server') throw new Error('Cannot start server when target is not server. https://err.sh/zeit/next.js/next-start-serverless')

this.buildId = this.readBuildId()
this.renderOpts = {
Expand Down

0 comments on commit 8b24103

Please sign in to comment.