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

Next.js项目启动报ReactCurrentDispatcher错误及依赖冲突求助

问题背景
  • 开发新手,跟随Next.js+Prisma+Postgres全栈Demo教程学习到第7步
  • 创建用户认证函数后执行npm run dev,抛出TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')错误
  • 尝试执行npm rm react react-dom && npm i -s react react-dom后,出现大量依赖冲突
  • 此前手动升级过部分依赖,但记不清具体模块,无法定位问题根源

初始报错信息

> hello-next@1.0.0 dev
> next

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
info  - Loaded env from C:\Users\myghq\workspace\personal-projects\blogr-nextjs-prisma\.env
C:\Users\myghq\workspace\personal-projects\blogr-nextjs-prisma\node_modules\react-dom\cjs\react-dom-server.node.development.js:320
var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
                                                  ^

TypeError: Cannot read properties of undefined (reading 'ReactCurrentDispatcher')
    at C:\Users\myghq\workspace\personal-projects\blogr-nextjs-prisma\node_modules\react-dom\cjs\react-dom-server.node.development.js:320:51
    at Object.<anonymous> (C:\Users\myghq\workspace\personal-projects\blogr-nextjs-prisma\node_modules\react-dom\cjs\react-dom-server.node.development.js:4382:5)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (C:\Users\myghq\workspace\personal-projects\blogr-nextjs-prisma\node_modules\react-dom\server.node.js:6:20)
    at Module._compile (node:internal/modules/cjs/loader:1469:14)

Node.js v20.17.0

依赖冲突报错信息

npm warn ERESOLVE overriding peer dependency
npm warn While resolving: next@12.0.10
npm warn Found: react@19.1.0
npm warn node_modules/react
npm warn   peer react@"^17.0.2 || ^18 || ^19" from next-auth@4.24.11
npm warn   node_modules/next-auth
npm warn     peer next-auth@"^4" from @next-auth/prisma-adapter@1.0.7
npm warn     node_modules/@next-auth/prisma-adapter
npm warn     1 more (the root project)
npm warn   2 more (react-markdown, styled-jsx)
npm warn
npm warn Could not resolve dependency:
npm warn peer react@"17.0.2" from react-dom@17.0.2
npm warn node_modules/react-dom
npm warn   peer react-dom@"^17.0.2 || ^18.0.0-0" from next@12.0.10
npm warn   node_modules/next
npm warn   1 more (next-auth)
npm warn ERESOLVE overriding peer dependency
npm warn While resolving: next@12.0.10
npm warn Found: react@19.1.0
npm warn node_modules/react
npm warn   peer react@"^17.0.2 || ^18 || ^19" from next-auth@4.24.11
npm warn   node_modules/next-auth
npm warn     peer next-auth@"^4" from @next-auth/prisma-adapter@1.0.7
npm warn     node_modules/@next-auth/prisma-adapter
npm warn     1 more (the root project)
npm warn   2 more (react-markdown, styled-jsx)
npm warn
npm warn Could not resolve dependency:
npm warn peer react@"17.0.2" from react-dom@17.0.2
npm warn node_modules/react-dom
npm warn   peer react-dom@"^17.0.2 || ^18.0.0-0" from next@12.0.10
npm warn   node_modules/next
npm warn   1 more (next-auth)
npm warn ERESOLVE overriding peer dependency
npm warn While resolving: next@12.0.10
npm warn Found: react@19.1.0
npm warn node_modules/react
npm warn   peer react@"^17.0.2 || ^18 || ^19" from next-auth@4.24.11
npm warn   node_modules/next-auth
npm warn     peer next-auth@"^4" from @next-auth/prisma-adapter@1.0.7
npm warn     node_modules/@next-auth/prisma-adapter
npm warn     1 more (the root project)
npm warn   2 more (react-markdown, styled-jsx)
npm warn
npm warn Could not resolve dependency:
npm warn peer react@"17.0.2" from react-dom@17.0.2
npm warn node_modules/react-dom
npm warn   peer react-dom@"^17.0.2 || ^18.0.0-0" from next@12.0.10
npm warn   node_modules/next
npm warn   1 more (next-auth)
npm error code ERESOLVE
npm error ERESOLVE could not resolve
npm error
npm error While resolving: next-auth@4.24.11
npm error Found: next@12.0.10
npm error node_modules/next
npm error   next@"12.0.10" from the root project
npm error
npm error Could not resolve dependency:
npm error peer next@"^12.2.5 || ^13 || ^14 || ^15" from next-auth@4.24.11
npm error node_modules/next-auth
npm error   peer next-auth@"^4" from @next-auth/prisma-adapter@1.0.7
npm error   node_modules/@next-auth/prisma-adapter
npm error     @next-auth/prisma-adapter@"^1.0.7" from the root project
npm error   next-auth@"^4.24.11" from the root project
npm error
npm error Conflicting peer dependency: next@15.3.0
npm error node_modules/next
npm error   peer next@"^12.2.5 || ^13 || ^14 || ^15" from next-auth@4.24.11
npm error   node_modules/next-auth
npm error     peer next-auth@"^4" from @next-auth/prisma-adapter@1.0.7
npm error     node_modules/@next-auth/prisma-adapter
npm error       @next-auth/prisma-adapter@"^1.0.7" from the root project
npm error     next-auth@"^4.24.11" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error C:\Users\myghq\AppData\Local\npm-cache\_logs\2025-04-12T15_50_38_299Z-eresolve-report.txt
npm error A complete log of this run can be found in: C:\Users\myghq\AppData\Local\npm-cache\_logs\2025-04-12T15_50_38_299Z-debug-0.log
解决步骤

1. 清理现有依赖环境

  • 删除本地依赖文件夹:
    Windows系统执行:rd /s /q node_modules
    macOS/Linux系统执行:rm -rf node_modules
  • 删除锁文件:del package-lock.json(Windows)或rm package-lock.json(macOS/Linux)
  • 清理npm缓存:npm cache clean --force

2. 统一核心依赖版本

打开项目根目录的package.json,将核心依赖替换为兼容的版本组合:

"dependencies": {
  "next": "^12.2.5",
  "react": "^18.2.0",
  "react-dom": "^18.2.0",
  "next-auth": "^4.24.11",
  "@next-auth/prisma-adapter": "^1.0.7",
  "prisma": "^4.16.2"
}

说明:Next.js 12.2.5+ 完美兼容React 18,同时满足next-auth 4.x的peer依赖要求,避免版本不匹配导致的冲突。

3. 重新安装依赖

执行以下命令安装依赖,跳过严格的peer依赖校验:

npm install --legacy-peer-deps

4. 验证项目启动

执行启动命令,确认错误是否解决:

npm run dev

后续注意事项

  • 不要随意执行npm install @latest单独升级某个依赖,极易引发版本不兼容问题
  • 跟随教程学习时,尽量使用教程推荐的依赖版本,减少冲突概率

内容的提问来源于stack exchange,提问作者Mike McGee

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 10:47:33