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

安装NextJS时遇TypeError: Cannot read properties of null报错求助

问题:安装NextJS依赖时触发Cannot read properties of null (reading 'matches')错误
  • 操作场景:正在按照NextJS官方教程完成安装步骤,执行命令:
    npm install react@latest react-dom@latest next@latest
    
  • 出现的错误:
    npm error Cannot read properties of null (reading 'matches')
    
  • 当前项目目录下的package.json内容:
    {}
    
  • 错误栈信息:
    15063 verbose stack TypeError: Cannot read properties of null (reading 'matches')
    15063 verbose stack     at Link.matches (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:1115:41)
    15063 verbose stack     at Link.canDedupe (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/node.js:1069:15)
    15063 verbose stack     at PlaceDep.pruneDedupable (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:426:14)
    15063 verbose stack     at new PlaceDep (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/place-dep.js:278:14)
    15063 verbose stack     at #buildDepStep (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:939:18)
    15063 verbose stack     at async Arborist.buildIdealTree (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js:203:7)
    15063 verbose stack     at async Promise.all (index 1)
    15063 verbose stack     at async Arborist.reify (/usr/local/lib/node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/reify.js:131:5)
    15063 verbose stack     at async Install.exec (/usr/local/lib/node_modules/npm/lib/commands/install.js:150:5)
    15063 verbose stack     at async module.exports (/usr/local/lib/node_modules/npm/lib/cli/entry.js:74:5)
    15064 verbose cwd /Users/bcarneiro/MyProjects/nextjs-dashboard
    15065 verbose Darwin 23.4.0
    15066 verbose node v20.15.0
    15067 verbose npm  v10.7.0
    15068 error Cannot read properties of null (reading 'matches')
    15069 verbose exit 1
    15070 verbose code 1
    
  • 附加信息:本人是前端开发新手,不清楚如何调试修复该问题,完整错误日志已记录。
可行的修复方案
  • 清理npm缓存,执行命令:
    npm cache clean --force
    
  • 若目录下存在node_modules文件夹或package-lock.json文件,先删除它们,再重新执行安装命令
  • 降级npm版本(当前使用的npm 10.7.0可能存在已知bug),执行命令:
    npm install -g npm@10.6.0
    
  • 改用官方推荐的项目创建方式,跳过手动安装依赖的步骤:
    npx create-next-app@latest
    
    按照终端提示完成项目初始化即可
  • 检查当前项目目录的读写权限,确保npm拥有足够权限写入文件

内容的提问来源于stack exchange,提问作者Bruno Carneiro

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.20 21:49:59