突然我的中间件在部署中停止工作。错误是:
> Build error occurred
NestedMiddlewareError: Nested Middleware is not allowed, found:
pages/_middleware
Please move your code to a single file at /middleware instead.
Run Code Online (Sandbox Code Playgroud)
Vercel 声明是:例如,pages/about/_middleware.ts 中的中间件可以将逻辑移动到存储库根目录中的 /middleware.ts。然后,可以使用条件语句仅在与 about/* 路径匹配时运行中间件:
当我使用pages/_middleware.ts运行本地构建时,它完成时没有错误,就像今天在生产中所做的那样。如果我将其更改为本地的pages/middleware.ts,则会失败:
./pages/middleware.ts
2:1 Error: next/server should not be imported outside of pages/_middleware.js. See: https://nextjs.org/docs/messages/no-server-import-in-page @next/next/no-server-import-in-page
Run Code Online (Sandbox Code Playgroud)
中间件文件:
import { getToken } from "next-auth/jwt";
import { NextRequest, NextResponse } from "next/server";
export async function middleware(req: NextRequest, res: NextResponse) {
if (req.nextUrl.pathname === "/") {
const session = await getToken({
req,
secret: process.env.JWT_SECRET, …Run Code Online (Sandbox Code Playgroud) 我创建了一个 Turborepo 测试项目,我想尝试在 Turborepo 根目录中设置的 ESlint 配置是否适用于我的 /apps 文件夹中的所有项目,结果发现它对我不起作用......我在哪里搞砸了向上 ?我正在关注这篇文章。
/packages/esling-config-custom/index.js
module.exports = {
extends: ["next", "turbo", "prettier"],
rules: {
"no-console": 2,
"@next/next/no-html-link-for-pages": "off",
},
};
Run Code Online (Sandbox Code Playgroud)
.eslintrc.js(Turborepo 的根目录)
module.exports = {
root: true,
// This tells ESLint to load the config from the package `eslint-config-custom`
extends: ["custom"],
settings: {
next: {
rootDir: ["apps/*/"],
},
},
};
Run Code Online (Sandbox Code Playgroud)
/apps/testing-app/.eslintrc.js
module.exports = {
...require("eslint-config-custom/index"),
parserOptions: {
tsconfigRootDir: __dirname,
project: "./tsconfig.json",
},
};
Run Code Online (Sandbox Code Playgroud)
/apps/testing-app/package.json
{
"name": "testing-app",
"version": "0.0.0",
"private": true,
"scripts": …Run Code Online (Sandbox Code Playgroud) 我无法解决标题中提到的错误:
错误:$VARIABLE 未在 Turbo.json 中列为依赖项
当我运行 npm run build 时,我收到两个变量的错误,而不是所有变量的错误,这对我来说很奇怪......
Error: $NEXT_STRIPE_SK is not listed as a dependency in turbo.json turbo/no-undeclared-env-vars
Error: $NEXT_PUBLIC_STRIPE_PK is not listed as a dependency in turbo.json turbo/no-undeclared-env-vars
Run Code Online (Sandbox Code Playgroud)
涡轮.json
{
"$schema": "https://turbo.build/schema.json",
"pipeline": {
"build": {
"dependsOn": [
"^build"
],
"outputs": [
"dist/**",
".next/**"
]
},
"order#build": {
"dependsOn": [
"^build"
],
"env": [
"NEXT_PUBLIC_STRIPE_PK",
"NEXT_STRIPE_SK"
],
"outputs": [
".next/**"
]
},
"lint": {
"outputs": []
},
"dev": {
"cache": false
}
},
"globalEnv": [
"NEXT_PUBLIC_SUPABASE_URL", …Run Code Online (Sandbox Code Playgroud)