[10:24:49.258] 10:24:49 [build] Rearranging server assets...
[10:24:49.270] 10:24:49 [@astrojs/vercel] Bundling function ../../../../dist/server/entry.mjs
[10:24:50.309] 10:24:50 [@astrojs/vercel] Copying static files to .vercel/output/static
[10:24:50.313] 10:24:50 [build] Server built in 4.57s
[10:24:50.315] 10:24:50 [build] Complete!
[10:24:50.596] Using TypeScript 5.7.3 (local user-provided)
[10:24:53.063] middleware.ts(1,8): error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled.
[10:24:53.064] middleware.ts(2,10): error TS1286: ESM syntax is not allowed in a CommonJS module when 'verbatimModuleSyntax' is enabled.
[10:24:53.064] middleware.ts(6,1): error TS1287: A top-level 'export' modifier cannot be used on value declarations in a CommonJS module when 'verbatimModuleSyntax' is enabled.
[10:24:53.064] middleware.ts(8,29): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.
[10:24:53.064] middleware.ts(9,36): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.
[10:24:53.064] middleware.ts(9,70): error TS1343: The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.
[10:24:53.064]
[10:24:53.284] Build Completed in /vercel/output [11s]
[10:24:53.439] Deploying outputs...
[10:24:54.961] Error: The Edge Function "middleware" is referencing unsupported modules:
I'm guessing its because I'm using the astro middleware module. Does that mean I would have to change it?
Vercel Staff
Oh I see. the Astro middleware is an Astro API, different than the Edge Middleware from Vercel.
So, following their docs is the right way to go. May I know the use case? Because, I feel that Vercel's Edge Middleware should also be able to do what you want to do with Astro Middleware.
Also, can you revert to your original code and then try removing the edgeMiddleware from the astro config to see if that changes the behaviour?
I'm using the middleware to intercept any request to /works and redirect the user to a random work from my portfolio. It just seems like Vercel is ignoring it entirely, as it won't redirect the users at all.
Note that it does work when the pages are not pre-rendered, but I would ideally want them to be. Astro's middleware does allow for SSG and SSR usage.