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

创建React应用时遭遇npm ERR! code ENOENT错误求助

解决create-react-app创建应用时找不到parser.ps1的报错

报错场景

执行 npx create-react-app first-app 创建React应用时,触发ENOENT错误,系统提示无法找到路径 G:\First react app\first-app\node_modules\.bin\parser.ps1,导致安装流程终止并自动删除生成的文件。

解决方法

  • 清除npm缓存后重试
    先清理npm缓存,再重新执行创建命令:

    npm cache clean --force
    npx create-react-app first-app
    
  • 临时调整PowerShell执行策略
    该报错可能因PowerShell执行策略限制脚本运行导致,临时放开权限:

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    

    执行时输入Y确认,完成应用创建后可恢复原策略:

    Set-ExecutionPolicy Restricted -Scope CurrentUser
    
  • 切换至Windows命令提示符执行
    打开cmd(命令提示符),在相同目录下运行创建命令:

    npx create-react-app first-app
    
  • 手动初始化项目并安装依赖
    若上述方法无效,可手动搭建项目结构:

    1. 创建目录并初始化npm:
      mkdir first-app
      cd first-app
      npm init -y
      
    2. 安装所需依赖:
      npm install react react-dom react-scripts cra-template --save-exact
      
    3. 在package.json中添加脚本:
      "scripts": {
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test",
        "eject": "react-scripts eject"
      }
      
    4. 创建public和src目录,添加基础文件(可参考正常React项目的目录结构,创建index.html、index.js等核心文件)。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 15:52:12