ChunQiuu 2022-06-12 13:51 采纳率: 75%
浏览 53
已结题

create-react-app创建项目默认代码报错

问题遇到的现象和发生背景 :

我新建了一个react项目,命令如下:

L:\code\test> create-react-app react-test
---create-react-app正在创建项目---
L:\code\test> npm start
PS L:\code\test> create-react-app react-test

Creating a new React app in L:\code\test\react-test.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...


added 1383 packages in 4m

192 packages are looking for funding
  run `npm fund` for details
Git repo not initialized Error: Command failed: git --version
    at checkExecSyncError (node:child_process:828:11)
    at execSync (node:child_process:902:15)
    at tryGitInit (L:\code\test\react-test\node_modules\react-scripts\scripts\init.js:46:5)
    at module.exports (L:\code\test\react-test\node_modules\react-scripts\scripts\init.js:276:7)
    at [eval]:3:14
    at Script.runInThisContext (node:vm:129:12)
    at Object.runInThisContext (node:vm:305:38)
    at node:internal/process/execution:75:19
    at [eval]-wrapper:6:22
    at evalScript (node:internal/process/execution:74:60) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 2604,
  stdout: null,
  stderr: null
}

Installing template dependencies using npm...
npm WARN deprecated source-map-resolve@0.6.0: See https://github.com/lydell/source-map-resolve#deprecated

added 39 packages in 21s

192 packages are looking for funding
  run `npm fund` for details
Removing template package using npm...


removed 1 package, and audited 1422 packages in 6s

192 packages are looking for funding
  run `npm fund` for details

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

Success! Created react-test at L:\code\test\react-test
Inside that directory, you can run several commands:

  npm start
    Starts the development server.

  npm run build
    Bundles the app into static files for production.

  npm test
    Starts the test runner.

  npm run eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you cant go back!

We suggest that you begin by typing:

  cd react-test
  npm start

Happy hacking!
问题相关代码:

就是create-react-app生成的默认代码

img

运行结果及报错内容

img

我的解答思路和尝试过的方法

重启过项目;
重新创建过项目

我想要达到的结果

无此报错

  • 写回答

3条回答 默认 最新

  • 虎子8 2022-06-12 14:25
    关注

    删除node_modules 重新安装一下。用yarn安装

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
  • 船长在船上 前端领域优质创作者 2022-06-12 14:22
    关注

    检查是否是版本原因

    评论
  • ChunQiuu 2022-06-13 18:40
    关注

    补充:运行npm audit 输出如下:

    # npm audit report
    
    nth-check  <2.0.1
    Severity: high
    Inefficient Regular Expression Complexity in nth-check - https://github.com/advisories/GHSA-rp65-9cf3-cjxr
    fix available via `npm audit fix --force`
    Will install react-scripts@2.1.3, which is a breaking change
    node_modules/svgo/node_modules/nth-check
      css-select  <=3.1.0
      Depends on vulnerable versions of nth-check
      node_modules/svgo/node_modules/css-select
        svgo  1.0.0 - 1.3.2
        Depends on vulnerable versions of css-select
        node_modules/svgo
          @svgr/plugin-svgo  <=5.5.0
          Depends on vulnerable versions of svgo
          node_modules/@svgr/plugin-svgo
            @svgr/webpack  4.0.0 - 5.5.0
            Depends on vulnerable versions of @svgr/plugin-svgo
            node_modules/@svgr/webpack
              react-scripts  >=2.1.4
              Depends on vulnerable versions of @svgr/webpack
              node_modules/react-scripts
    
    6 high severity vulnerabilities
    
    To address all issues (including breaking changes), run:
      npm audit fix --force
    
    

    再补充:

    Failed to compile.
    
    Plugin "react" was conflicted between "package.json » eslint-config-react-app » L:\code\test\react-test\node_modules\eslint-config-react-app\base.js" and "BaseConfig » L:\code\Test\react-test\node_modules\eslint-config-react-app\base.js".
    ERROR in Plugin "react" was conflicted between "package.json » eslint-config-react-app » L:\code\test\react-test\node_modules\eslint-config-react-app\base.js" and "BaseConfig » L:\code\Test\react-test\node_modules\eslint-config-react-app\base.js".
    
    webpack compiled with 1 error
    
    评论 编辑记录
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 6月25日
  • 已采纳回答 6月17日
  • 创建了问题 6月12日

悬赏问题

  • ¥100 正常上网,内部网页无法打开
  • ¥15 组件库引入并使用在若依框架未展示
  • ¥149 关于#使用python 的Flash Echarts+ajax+mysql动态数据实现饼图#的问题,请各位专家解答!
  • ¥15 RichTextBox中追加文本时报错
  • ¥15 关于c语言的学习问题
  • ¥15 activity升级到flowable工作流act_ge_bytearray的草稿json数据复制到act_de_model 的model_editor_json的脚本
  • ¥15 cvi使用CreateThread创建线程时,出现存储空间不足无法处理此命令的错误
  • ¥15 求苹果推信imessage批量推信技术
  • ¥15 ubuntu 22.04 系统盘空间不足。隐藏的docker空间占用?(相关搜索:移动硬盘|管理系统)
  • ¥15 c++ word自动化,为什么可用接口是空的?