Unverified Commit dc13c12c authored by Yixuan Xu's avatar Yixuan Xu Committed by GitHub

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.
parent b1de1d10
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment