@@ -2,13 +2,24 @@ const { Server } = require('http')
2
2
const path = require ( 'path' )
3
3
4
4
const { Bridge } = require ( '@vercel/node/dist/bridge' )
5
- // This path is specific to next@canary . In a live version we'd resolve various versions of next
6
- const NextServer = require ( 'next/dist/server/next-server' ) . default
7
5
8
6
const makeHandler =
9
7
( ) =>
10
8
// We return a function and then call `toString()` on it to serialise it as the launcher function
11
9
( conf , app ) => {
10
+ let nextServerPath
11
+
12
+ try {
13
+ // next >= 11.0.1. Yay breaking changes in patch releases!
14
+ nextServerPath = require . resolve ( 'next/dist/server/next-server' )
15
+ } catch {
16
+ // next < 11.0.1
17
+ // eslint-disable-next-line node/no-missing-require
18
+ nextServerPath = require . resolve ( 'next/dist/next-server/server/next-server' )
19
+ }
20
+ // eslint-disable-next-line import/no-dynamic-require
21
+ const { default : NextServer } = require ( nextServerPath )
22
+
12
23
const nextServer = new NextServer ( {
13
24
conf,
14
25
dir : path . resolve ( __dirname , app ) ,
@@ -61,8 +72,6 @@ const getHandler = ({ isODB = false, publishDir = '../../../.next', appDir = '..
61
72
const { Server } = require("http");
62
73
// We copy the file here rather than requiring from the node module
63
74
const { Bridge } = require("./bridge");
64
- // Specific to this Next version
65
- const NextServer = require("next/dist/server/next-server").default;
66
75
const { builder } = require("@netlify/functions");
67
76
const { config } = require("${ publishDir } /required-server-files.json")
68
77
const path = require("path");
0 commit comments