refactor: add named export in next/server (#39381)

## Bug
When using next/server in different environment ([vitest](https://vitest.dev/)), named import will have runtime error.

```tsx
import { NextRequest } from 'next/server'
// TypeError: NextRequest is not a constructor
const request = new NextRequest()
```
This is conflicted with current `server.d.ts` files.

## Alternative
* reverte current `server.js` to esm, them compiled it to cjs.
This commit is contained in:
Yixuan Xu 2022-08-08 00:17:15 +08:00 committed by GitHub
parent b1de1d1078
commit dc13c12ccc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -14,4 +14,13 @@ if (typeof URLPattern !== 'undefined') {
serverExports.URLPattern = URLPattern
}
// https://nodejs.org/api/esm.html#commonjs-namespaces
// When importing CommonJS modules, the module.exports object is provided as the default export
module.exports = serverExports
// make import { xxx } from 'next/server' work
exports.NextRequest = serverExports.NextRequest
exports.NextResponse = serverExports.NextResponse
exports.userAgentFromString = serverExports.userAgentFromString
exports.userAgent = serverExports.userAgent
exports.URLPattern = serverExports.URLPattern