We have a Next 13 project (using the pages router) and we’re having some problems with middleware.
Middleware defined in src/middleware.ts works, but then I have problems defining additional edge functions in the netlify.toml
To work around this I’ve tried to switch to explicitly defining the middleware in the netlify.toml, but I seem to be having problems with the edge function npm package beta
[edge_functions]]
path = '/*'
function = 'middleware'
The only imports in the 2 files defined are
import { NextMiddleware, NextResponse } from "next/server";
Relevant log:
3:02:22 PM: Edge Functions bundling
3:02:22 PM: ────────────────────────────────────────────────────────────────
3:02:22 PM:
3:02:22 PM: Packaging Edge Functions from apps/nextjs/netlify/edge-functions directory:
3:02:22 PM: - middleware
3:02:22 PM: - subdomain-redirect
3:02:22 PM: error: Uncaught (in promise) Error: Relative import path "next/server" not prefixed with / or ./ or ../ and not in import map from "file:///root/apps/nextjs/netlify/edge-functions/middleware.ts"
3:02:22 PM: const ret = new Error(getStringFromWasm0(arg0, arg1));
3:02:22 PM: ^
3:02:22 PM: at __wbg_new_d258248ed531ff54 (file:///opt/buildhome/node-deps/node_modules/@netlify/edge-bundler/deno/vendor/deno.land/x/eszip@v0.55.2/eszip_wasm.generated.js:443:19)