This commit is contained in:
eric
2026-03-12 04:11:29 -05:00
parent 6f4e287ca3
commit 528044db7d
6 changed files with 21 additions and 52 deletions

View File

@@ -10,37 +10,9 @@ Error: Failed to find Server Action. This request might be from an older or newe
**原因**Next.js 为 Server Actions 使用加密密钥,每次构建会重新生成。部署后客户端可能仍缓存旧版本 JS导致请求的 action ID 与服务器不匹配。
**解决方案**在**构建时**设置固定加密密钥 `NEXT_SERVER_ACTIONS_ENCRYPTION_KEY`,使多次部署使用相同密钥
**解决方案**项目已内置 `config/server-actions.key`,构建时 `next.config.ts` 会自动加载,无需手动配置。直接执行 `pnpm build` 即可
### 步骤
1. **生成密钥**(仅需执行一次,之后复用同一密钥):
```bash
node scripts/generate-encryption-key.js
```
2. **在构建前设置环境变量**
```bash
export NEXT_SERVER_ACTIONS_ENCRYPTION_KEY="<上一步输出的 base64 字符串>"
pnpm build
```
或在 `.env` / `.env.production` 中添加:
```
NEXT_SERVER_ACTIONS_ENCRYPTION_KEY=<base64 字符串>
```
3. **重新构建并重启**
```bash
pnpm build
pm2 restart vip
```
4. **建议用户清除缓存**部署后若仍有问题可让用户执行硬刷新Ctrl+Shift+R或清除浏览器缓存。
部署后若仍有问题可让用户执行硬刷新Ctrl+Shift+R或清除浏览器缓存。
---
@@ -50,8 +22,7 @@ Error: Failed to find Server Action. This request might be from an older or newe
# 1. 安装依赖
pnpm install
# 2. 设置 NEXT_SERVER_ACTIONS_ENCRYPTION_KEY 后构建
export NEXT_SERVER_ACTIONS_ENCRYPTION_KEY="你的密钥"
# 2. 构建(自动加载 config/server-actions.key
pnpm build
# 3. 启动