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

Turborepo Monorepo中执行next build时出现useContext相关预渲染错误求助

Turborepo Monorepo中执行next build时出现useContext相关预渲染错误求助

大家好,我目前在维护一个包含两个NextJS项目的Turborepo monorepo,最近执行next build的时候遇到了一个useContext相关的预渲染错误,卡了好一会儿没解决,想请各位帮忙分析下原因。

具体的错误信息如下:

TypeError: Cannot read properties of null (reading 'useContext')
Error occurred prerendering page "/404".
TypeError: Cannot read properties of null (reading 'useContext') at exports.useContext (/Users/user/dev/repos/repo-root/node_modules/styled-jsx/node_modules/react/cjs/react.production.js:488:33)

下面是两个项目的package.json配置:

App A(docs)的package.json

{
  "name": "docs",
  "version": "0.1.0",
  "type": "module",
  "private": true,
  "scripts": {
    "dev": "next dev --turbopack -p 3001",
    "build": "next build",
    "start": "next start",
    "lint": "next lint --max-warnings 0",
    "check-types": "tsc --noEmit"
  },
  "dependencies": {
    "next": "^15.2.1",
    "react": "^19.1.0",
    "react-dom": "^19.1.0"
  },
  "devDependencies": {
    "@types/node": "^22.13.10",
    "@types/react": "19.0.0",
    "@types/react-dom": "19.0.0",
    "eslint": "^9.22.0",
    "typescript": "5.8.2"
  }
}

App B(app)的package.json

{
  "name": "app",
  "version": "0.1.0",
  "type": "module",
  "private": true,
  "scripts": {
    "dev": "next dev --turbopack -p 3002",
    "build": "next build",
    "start": "next start",
    "lint": "next lint --max-warnings 0",
    "check-types": "tsc --noEmit"
  },
  "dependencies": {
    "next": "^15.2.1",
    "react": "19.0.0",
    "react-dom": "19.0.0"
  },
  "devDependencies": {
    "@types/node": "^22.13.10",
    "@types/react": "19.0.0",
    "@types/react-dom": "19.0.0",
    "eslint": "^9.22.0",
    "typescript": "5.8.2"
  }
}

我已经尝试过创建自定义的404页面和错误页面,但问题依然存在。有没有朋友遇到过类似的情况,或者能给我一些排查方向的建议?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.08 11:13:09