未捕获的语法错误:使用 Next Middleware 时出现意外的标记“<”

Bor*_*ter 7 middleware reactjs next.js

我有一个简单的中间件设置,用于检查用户是否使用 zustand 存储中的布尔值登录,并相应地将用户重定向到登录页面。这是根据文档

   import { NextResponse } from "next/server";
    import type { NextRequest } from "next/server";
    import { useAuthStore } from "./zustand/store";
    
    export function middleware(request: NextRequest) {
      const loggedIn = useAuthStore.getState().loggedIn;
      if (!loggedIn) {
        const url = request.nextUrl.clone();
        url.pathname = "/login";
        return NextResponse.rewrite(url);
      } else {
        return NextResponse.rewrite(request.nextUrl.clone());
      }
    }
Run Code Online (Sandbox Code Playgroud)

然而,当我使用这个中间件时,我得到

react-refresh.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at react-refresh.js?ts=1661359264454:1:1)
18:41:04.842 webpack.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at webpack.js?ts=1661359264454:1:1)
18:41:04.842 main.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at main.js?ts=1661359264454:1:1)
18:41:04.909 _app.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at _app.js?ts=1661359264454:1:1)
18:41:04.924 index.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at index.js?ts=1661359264454:1:1)
18:41:04.925 _buildManifest.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at _buildManifest.js?ts=1661359264454:1:1)
18:41:04.925 _ssgManifest.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at _ssgManifest.js?ts=1661359264454:1:1)
Run Code Online (Sandbox Code Playgroud)