Skip to content

Commit 2d2c198

Browse files
authored
fix: server loading (#24)
1 parent 81fbece commit 2d2c198

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/templates/getHandler.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@ const makeHandler =
77
() =>
88
// We return a function and then call `toString()` on it to serialise it as the launcher function
99
(conf, app) => {
10-
let nextServerPath
11-
10+
let NextServer
1211
try {
1312
// next >= 11.0.1. Yay breaking changes in patch releases!
14-
nextServerPath = require.resolve('next/dist/server/next-server')
13+
NextServer = require('next/dist/server/next-server').default
1514
} 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')
15+
// Probably an old version of next
16+
}
17+
18+
if (!NextServer) {
19+
try {
20+
// next < 11.0.1
21+
// eslint-disable-next-line node/no-missing-require, import/no-unresolved
22+
NextServer = require('next/dist/next-server/server/next-server').default
23+
} catch {
24+
throw new Error('Could not find Next.js server')
25+
}
1926
}
20-
// eslint-disable-next-line import/no-dynamic-require
21-
const { default: NextServer } = require(nextServerPath)
2227

2328
const nextServer = new NextServer({
2429
conf,

0 commit comments

Comments
 (0)