Skip to content

Commit 8b24103

Browse files
dav-istimneutkens
authored andcommitted
Throw Error When Running next start on Serverless Build (vercel#6166)
Fixes vercel#6144
1 parent 1475491 commit 8b24103

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

errors/next-start-serverless.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Using `next start` with `target` not set to `server`
2+
3+
#### Why This Error Occurred
4+
5+
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.
6+
7+
#### Possible Ways to Fix It
8+
9+
Use a different handler than `next start` when testing a serverless **production** build, otherwise just use `next dev`.

packages/next-server/server/next-server.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ export default class Server {
4747

4848
// Only serverRuntimeConfig needs the default
4949
// publicRuntimeConfig gets it's default in client/index.js
50-
const {serverRuntimeConfig = {}, publicRuntimeConfig, assetPrefix, generateEtags} = this.nextConfig
50+
const {serverRuntimeConfig = {}, publicRuntimeConfig, assetPrefix, generateEtags, target} = this.nextConfig
51+
52+
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')
5153

5254
this.buildId = this.readBuildId()
5355
this.renderOpts = {

0 commit comments

Comments
 (0)