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

使用npx create-react-app建项目遇ERR_INVALID_PACKAGE_CONFIG错误求助

解决npx create-react-app报错ERR_INVALID_PACKAGE_CONFIG的方案

问题场景

执行命令:

PS C:\Users\B E S T\Desktop\ReactTuts> npx create-react-app feastproj

出现如下错误:

node:internal/modules/package_json_reader:110
const parsed = modulesBinding.readPackageJSON(
^

Error: Invalid package config C:\Users\B E S T\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\which\package.json.
at read (node:internal/modules/package_json_reader:110:33)
at readPackage (node:internal/modules/package_json_reader:128:10)
at resolveExports (node:internal/modules/cjs/loader:592:15)
at Module._findPath (node:internal/modules/cjs/loader:673:31)
at Module._resolveFilename (node:internal/modules/cjs/loader:1135:27)
at Module._load (node:internal/modules/cjs/loader:990:27)
at Module.require (node:internal/modules/cjs/loader:1237:19)
at require (node:internal/modules/helpers:176:18)
at Object. (C:\Users\B E S T\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\cross-spawn\lib\util\resolveCommand.js:4:15)
at Module._compile (node:internal/modules/cjs/loader:1378:14) {
code: 'ERR_INVALID_PACKAGE_CONFIG'
}

当前Node.js版本为v21.6.2,已尝试npm cache clear --force和npm config set registry http://registry.npmjs.org/操作,问题仍未解决。

排查处理步骤

  • 手动删除损坏的npx临时缓存目录
    错误提示明确指出C:\Users\B E S T\AppData\Local\npm-cache\_npx\c67e74de0542c87c下的which包package.json无效,直接找到该文件夹删除,再重新执行创建命令。
  • 切换Node.js至LTS稳定版本
    Node v21为开发预览版,存在兼容性问题,建议更换为LTS版本(如v20.x或v18.x):
    1. 卸载当前Node.js
    2. 安装nvm(Windows版本)管理Node版本
    3. 执行nvm install 20安装LTS版本,再用nvm use 20切换到该版本
  • 指定create-react-app版本强制创建
    执行命令npx create-react-app@latest feastproj --force,--force参数会强制重新拉取所有依赖,规避缓存损坏导致的问题。
  • 更换无空格的工作目录
    当前用户目录名称B E S T包含空格,可能引发路径解析异常,尝试在无空格的目录(如C:\ReactProjects)下执行创建命令。
  • 全局安装create-react-app后创建项目
    先执行npm install -g create-react-app全局安装工具,再执行create-react-app feastproj创建项目,绕开npx的临时缓存问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.29 08:32:40