Skip to content

Commit

Permalink
Fix next/server being required during build (#39310)
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Aug 4, 2022
1 parent 11c9d42 commit de41597
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/next/server.js
@@ -1,4 +1,4 @@
module.exports = {
const serverExports = {
NextRequest: require('next/dist/server/web/spec-extension/request')
.NextRequest,
NextResponse: require('next/dist/server/web/spec-extension/response')
Expand All @@ -7,6 +7,11 @@ module.exports = {
.userAgentFromString,
userAgent: require('next/dist/server/web/spec-extension/user-agent')
.userAgent,
}

if (typeof URLPattern !== 'undefined') {
// eslint-disable-next-line no-undef
URLPattern: URLPattern,
serverExports.URLPattern = URLPattern
}

module.exports = serverExports
5 changes: 5 additions & 0 deletions test/unit/web-runtime/next-server-node.test.ts
@@ -0,0 +1,5 @@
import 'next/dist/server/node-polyfill-fetch'

it('should be able to require next/server outside edge', () => {
require('next/server')
})

0 comments on commit de41597

Please sign in to comment.