【问题标题】:why i can not create a new react app with npm?为什么我不能用 npm 创建一个新的 React 应用程序?
【发布时间】:2022-11-29 20:56:57
【问题描述】:

我打算用 npm 创建一个新的 React 应用程序,但它不起作用,而且我每次尝试时都会遇到太多错误 有人能帮助我吗?:(

我在cmd中输入了这一行

npx create-react-app my-app

和错误:

npm ERR! code ECONNRESET
npm ERR! syscall read
npm ERR! errno -4077
npm ERR! network read ECONNRESET
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\sobha\AppData\Local\npm-cache\_logs\2022-11-29T11_57_33_191Z-debug-0.log

Aborting installation.
  npm install --no-audit --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.

Deleting generated file... node_modules
Deleting generated file... package.json
Deleting my-app/ from C:\Users\sobha\Desktop\react
Done.

【问题讨论】:

  • 因为您的网络连接似乎有问题,如错误消息所述..

标签: javascript node.js reactjs frontend npm-install


【解决方案1】:

如果您使用的是 VPN,请关闭 VPN 并重试。

【讨论】:

    【解决方案2】:

    首先检查您的网络连接,然后

    npm cache clean --force
    
    npm create react-app 
    

    【讨论】:

      【解决方案3】:

      问题很可能是您被 ISP 或公司的防火墙/代理阻止访问该网站。使用上述方法更快更容易,但它也不安全,因为它无法验证您连接到正确的网站。要检查您是否被阻止,只需在浏览器中访问 registry.npmjs.org。你应该得到一些文本回来。

      选项1

      尝试这个:

      npm config set registry http://registry.npmjs.org/
      

      这样 npm 请求 http url 而不是 https。

      然后尝试相同的 npx create-react-app my-app 命令。

      选项 2

      您可能还想检查您的 NPM 代理设置并可能将其删除。

      npm config get proxy
      npm config rm proxy
      npm config rm https-proxy
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-07-22
        • 2019-06-16
        • 1970-01-01
        • 1970-01-01
        • 2021-11-27
        • 1970-01-01
        相关资源
        最近更新 更多