diff --git a/errors/next-start-serverless.md b/errors/next-start-serverless.md new file mode 100644 index 0000000000000000000000000000000000000000..483f024d99d4cf985622008ecfba4f5d9875e466 --- /dev/null +++ b/errors/next-start-serverless.md @@ -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`. diff --git a/packages/next-server/server/next-server.ts b/packages/next-server/server/next-server.ts index 2953ff32aa5754a8b2c02a5843125cfb6cb5d7d5..54b15b4925976ce07879a05bb442445cd75366fe 100644 --- a/packages/next-server/server/next-server.ts +++ b/packages/next-server/server/next-server.ts @@ -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 = {