Функция промежуточного программного обеспечения от Auth.js превышает предел Vercel 1 MBJavascript

Форум по Javascript
Ответить
Anonymous
 Функция промежуточного программного обеспечения от Auth.js превышает предел Vercel 1 MB

Сообщение Anonymous »

Мое приложение использует auth.js (nextauth.js v5) для аутентификации. В Local это работает нормально, но при развертывании для проблем с Vercel возникают с «размером функции промежуточного программного обеспечения». Я попытался «уменьшить» файл, который я не могу сделать.// middleware.ts
import { auth } from "./lib/auth";
import { NextResponse } from "next/server";

export default auth(function middleware(req) {
const { auth, nextUrl } = req;
const { pathname } = nextUrl;

if (!auth) {
return NextResponse.redirect(new URL("/login", req.url));
}

if (pathname.startsWith("/admin") && auth.user.role !== "ADMIN") {
return NextResponse.redirect(new URL("/", req.url));
}

return NextResponse.next();
});

export const config = {
matcher: ["/checkout", "/profile", "/admin/:path*"],
};
< /code>
[09:57:28.046] ▲ Next.js 15.3.2
[09:57:28.047]
[09:57:28.073] Creating an optimized production build ...
[09:57:59.151] ⚠ Compiled with warnings in 3.0s
[09:57:59.152]
[09:57:59.152] ./node_modules/@prisma/client/runtime/wasm-engine-edge.js
[09:57:59.152] A Node.js API is used (setImmediate at line: 11) which is not supported in the Edge Runtime.
[09:57:59.152] Learn more: https://nextjs.org/docs/api-reference/edge-runtime
[09:57:59.152]
[09:57:59.152] Import trace for requested module:
[09:57:59.152] ./node_modules/@prisma/client/runtime/wasm-engine-edge.js
[09:57:59.152] ./node_modules/.prisma/client/wasm.js
[09:57:59.152] ./node_modules/.prisma/client/default.js
[09:57:59.152] ./node_modules/@prisma/client/default.js
[09:57:59.153] ./lib/prisma.ts
[09:57:59.153] ./lib/auth.ts
[09:57:59.153]
[09:57:59.153] ./node_modules/@prisma/debug/dist/index.mjs
[09:57:59.153] A Node.js API is used (process.stdout at line: 45) which is not supported in the Edge Runtime.
[09:57:59.153] Learn more: https://nextjs.org/docs/api-reference/edge-runtime
[09:57:59.153]
[09:57:59.153] Import trace for requested module:
[09:57:59.157] ./node_modules/@prisma/debug/dist/index.mjs
[09:57:59.158] ./node_modules/@prisma/driver-adapter-utils/dist/index.mjs
[09:57:59.158] ./node_modules/@prisma/adapter-neon/dist/index.mjs
[09:57:59.158] ./lib/prisma.ts
[09:57:59.158] ./lib/auth.ts
[09:57:59.158]
[09:57:59.158] ./node_modules/@prisma/debug/dist/index.mjs
[09:57:59.158] A Node.js API is used (process.stdout at line: 45) which is not supported in the Edge Runtime.
[09:57:59.158] Learn more: https://nextjs.org/docs/api-reference/edge-runtime
[09:57:59.159]
[09:57:59.159] Import trace for requested module:
[09:57:59.159] ./node_modules/@prisma/debug/dist/index.mjs
[09:57:59.159] ./node_modules/@prisma/driver-adapter-utils/dist/index.mjs
[09:57:59.159] ./node_modules/@prisma/adapter-neon/dist/index.mjs
[09:57:59.159] ./lib/prisma.ts
[09:57:59.159] ./lib/auth.ts
[09:57:59.160]
[09:57:59.160] ./node_modules/bcryptjs/index.js
[09:57:59.161] A Node.js module is loaded ('crypto' at line 32) which is not supported in the Edge Runtime.
[09:57:59.161] Learn More: https://nextjs.org/docs/messages/node-m ... ge-runtime
[09:57:59.161]
[09:57:59.161] Import trace for requested module:
[09:57:59.161] ./node_modules/bcryptjs/index.js
[09:57:59.161] ./lib/auth.ts
[09:57:59.161]
[09:57:59.161] ./node_modules/bcryptjs/index.js
[09:57:59.161] A Node.js API is used (process.nextTick at line: 337) which is not supported in the Edge Runtime.
[09:57:59.162] Learn more: https://nextjs.org/docs/api-reference/edge-runtime
[09:57:59.162]
[09:57:59.162] Import trace for requested module:
[09:57:59.162] ./node_modules/bcryptjs/index.js
[09:57:59.162] ./lib/auth.ts
[09:57:59.162]
[09:57:59.162] ./node_modules/bcryptjs/index.js
[09:57:59.162] A Node.js API is used (setImmediate at line: 338) which is not supported in the Edge Runtime.
[09:57:59.162] Learn more: https://nextjs.org/docs/api-reference/edge-runtime
[09:57:59.162]
[09:57:59.162] Import trace for requested module:
[09:57:59.163] ./node_modules/bcryptjs/index.js
[09:57:59.163] ./lib/auth.ts
[09:57:59.163]
[09:57:59.163] ./node_modules/bcryptjs/index.js
[09:57:59.164] A Node.js API is used (setImmediate at line: 339) which is not supported in the Edge Runtime.
[09:57:59.164] Learn more: https://nextjs.org/docs/api-reference/edge-runtime
[09:57:59.164]
[09:57:59.164] Import trace for requested module:
[09:57:59.164] ./node_modules/bcryptjs/index.js
[09:57:59.164] ./lib/auth.ts
[09:57:59.164]
[09:57:59.164] ./node_modules/bcryptjs/index.js
[09:57:59.164] A Node.js API is used (process.nextTick at line: 340) which is not supported in the Edge Runtime.
[09:57:59.164] Learn more: https://nextjs.org/docs/api-reference/edge-runtime
[09:57:59.164]
[09:57:59.165] Import trace for requested module:
[09:57:59.166] ./node_modules/bcryptjs/index.js
[09:57:59.166] ./lib/auth.ts
[09:57:59.166]
[09:58:10.903] ✓ Compiled successfully in 38.0s
[09:58:10.910] Linting and checking validity of types ...
[09:58:24.856] Collecting page data ...
[09:58:29.221] Generating static pages (0/17) ...
[09:58:30.668] Generating static pages (4/17)
[09:58:30.669] Generating static pages (8/17)
[09:58:31.101] items no checkout: []
[09:58:31.102] Generating static pages (12/17)
[09:58:31.252] ✓ Generating static pages (17/17)
[09:58:31.992] Finalizing page optimization ...
[09:58:31.997] Collecting build traces ...
[09:58:46.060]
[09:58:46.085] Route (app) Size First Load JS
[09:58:46.085] ┌ ƒ / 11 kB 177 kB
[09:58:46.085] ├ ○ /_not-found 152 B 101 kB
[09:58:46.085] ├ ƒ /about-us 2.87 kB 154 kB
[09:58:46.085] ├ ƒ /admin 152 B 101 kB
[09:58:46.085] ├ ƒ /admin/orders 2.86 kB 160 kB
[09:58:46.085] ├ ƒ /admin/orders/[id] 615 B 157 kB
[09:58:46.085] ├ ƒ /api/auth/[...nextauth] 152 B 101 kB
[09:58:46.085] ├ ƒ /api/cart 152 B 101 kB
[09:58:46.085] ├ ƒ /api/webhooks/stripe 152 B 101 kB
[09:58:46.085] ├ ƒ /cart 5.9 kB 131 kB
[09:58:46.085] ├ ƒ /checkout 9.21 kB 118 kB
[09:58:46.085] ├ ƒ /contact 6.1 kB 213 kB
[09:58:46.085] ├ ○ /login 4.72 kB 145 kB
[09:58:46.085] ├ ƒ /product/[id] 3.15 kB 130 kB
[09:58:46.085] ├ ƒ /profile 23 kB 203 kB
[09:58:46.085] ├ ○ /register 4.3 kB 150 kB
[09:58:46.085] └ ƒ /shop 2.63 kB 132 kB
[09:58:46.085] + First Load JS shared by all 101 kB
[09:58:46.085] ├ chunks/1684-602fe482d4f67271.js 45.9 kB
[09:58:46.085] ├ chunks/4bd1b696-70e5911b2dee13fe.js 53.2 kB
[09:58:46.085] └ other shared chunks (total) 1.93 kB
[09:58:46.085]
[09:58:46.085]
[09:58:46.085] ƒ Middleware 193 kB
[09:58:46.085]
[09:58:46.086] ○ (Static) prerendered as static content
[09:58:46.086] ƒ (Dynamic) server-rendered on demand
[09:58:46.086]
[09:58:46.264] Traced Next.js server files in: 92.792ms
[09:58:46.521] Created all serverless functions in: 256.311ms
[09:58:46.732] Collected static files (public/, static/, .next/static): 14.489ms
[09:58:46.915] Build Completed in /vercel/output [2m]
[09:58:47.089] Deploying outputs...
[09:59:00.290] Error: The Edge Function "middleware" size is 1.07 MB and your plan size limit is 1 MB. Learn More: https://vercel.link/edge-function-size
< /code>
Expected: Deploy Next.js app with Auth.js authentication to Vercel
Result: Error with middleware function size in edge enviroment

Подробнее здесь: https://stackoverflow.com/questions/797 ... 1-mb-limit
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»