You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NextJS 13 + next-auth正则表达式无效语法错误求助

解决npm run dev时的正则表达式语法错误

执行npm run dev时出现以下错误:

SyntaxError: Invalid regular expression: /^/_next/data/development/api/auth/[...nextauth}.json$/: Unterminated character class at new RegExp () at buildDataRoute (/home/plamen/Code/promptopia/node_modules/next/dist/server/lib/router-utils/build-data-route.js:34:69) at Watchpack. (/home/plamen/Code/promptopia/node_modules/next/dist/server/lib/router-utils/setup-dev.js:875:70)

问题原因

错误源于Next.js动态路由文件命名错误:NextAuth的动态路由文件名应为[...nextauth].js(或.ts),但你当前的文件名末尾用了大括号}而非方括号],导致生成的正则表达式语法无效。

修复步骤

  • 找到项目中app/api/auth/目录下的对应文件,将文件名从[...nextauth}.js(或.ts)修改为[...nextauth].js(或.ts)。
  • 停止当前npm run dev服务,重新执行该命令启动项目,错误即可解决。

内容的提问来源于stack exchange,提问作者Plamen Petrov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 00:37:01