【问题标题】:npx create-react-app projectName causing errornpx create-react-app projectName 导致错误
【发布时间】:2020-12-17 07:40:13
【问题描述】:

我正在使用第一个命令创建一个反应应用程序; npm init 然后是第二个 npx create-react-app projectName,但是它给出了这个错误:

npm ERR! code ETIMEDOUT
npm ERR! errno ETIMEDOUT
npm ERR! network request to http://registry.npmjs.org/create-react-app failed, reason: connect ETIMEDOUT 104.16.22.35:80
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\amrish patidar\AppData\Roaming\npm-cache\_logs\2020-12-17T07_28_05_673Z-debug.log

我的 npm 配置列表如下

npm config list

    ; cli configs
    metrics-registry = "http://registry.npmjs.org/"
    scope = ""
    user-agent = "npm/6.14.9 node/v14.15.2 win32 x64"
    
    ; userconfig C:\Users\amrish patidar\.npmrc
    registry = "http://registry.npmjs.org/"
    strict-ssl = true
    
    ; builtin config undefined
    prefix = "C:\\Users\\amrish patidar\\AppData\\Roaming\\npm"
    
    ; node bin location = C:\Program Files\nodejs\node.exe
    ; cwd = C:\Users\amrish patidar
    ; HOME = C:\Users\amrish patidar
    ; "npm config ls -l" to show all defaults.

debug.log 文件

 C:\Users\amrish patidar\AppData\Roaming\npm-cache\_logs\2020-12-17T07_28_05_673Z-debug.log


    0 info it worked if it ends with ok
    1 verbose cli [
    1 verbose cli   'C:\\Program Files\\nodejs\\node.exe',
    1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
    1 verbose cli   'install',
    1 verbose cli   'create-react-app'
    1 verbose cli ]
    2 info using npm@6.14.9
    3 info using node@v14.15.2
    4 verbose config Skipping project config: C:\Users\amrish patidar/.npmrc. (matches userconfig)
    5 verbose npm-session c45391ce1f743672
    6 silly install loadCurrentTree
    7 silly install readLocalPackageData
    8 silly fetchPackageMetaData error for create-react-app@latest request to http://registry.npmjs.org/create-react-app failed, reason: connect ETIMEDOUT 104.16.17.35:80
    9 timing stage:rollbackFailedOptional Completed in 1ms
    10 timing stage:runTopLevelLifecycles Completed in 133456ms
    11 verbose type system
    12 verbose stack FetchError: request to http://registry.npmjs.org/create-react-app failed, reason: connect ETIMEDOUT 104.16.17.35:80
    12 verbose stack     at ClientRequest.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\index.js:68:14)
    12 verbose stack     at ClientRequest.emit (events.js:315:20)
    12 verbose stack     at Socket.socketErrorListener (_http_client.js:469:9)
    12 verbose stack     at Socket.emit (events.js:315:20)
    12 verbose stack     at emitErrorNT (internal/streams/destroy.js:106:8)
    12 verbose stack     at emitErrorCloseNT (internal/streams/destroy.js:74:3)
    12 verbose stack     at processTicksAndRejections (internal/process/task_queues.js:80:21)
    13 verbose cwd C:\Users\amrish patidar
    14 verbose Windows_NT 10.0.19041
    15 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "create-react-app"
    16 verbose node v14.15.2
    17 verbose npm  v6.14.9
    18 error code ETIMEDOUT
    19 error errno ETIMEDOUT
    20 error network request to http://registry.npmjs.org/create-react-app failed, reason: connect ETIMEDOUT 104.16.17.35:80
    21 error network This is a problem related to network connectivity.
    21 error network In most cases you are behind a proxy or have bad network settings.
    21 error network
    21 error network If you are behind a proxy, please make sure that the
    21 error network 'proxy' config is set properly.  See: 'npm help config'
    22 verbose exit [ 1, true ]

【问题讨论】:

标签: reactjs npm npm-registry


【解决方案1】:

也许你在某些代理背后,

试试这个

转到设置>网络和 Internet>代理,然后关闭自动检测 Windows 上自动代理设置下的设置。然后它应该可以正常工作

【讨论】:

  • 我已经这样做了,但还是不行。
  • npm 配置删除代理
  • npm config rm proxy && npm config rm https-proxy
  • 好的,一般设置了代理或者网络不稳定都会出现这个问题。
  • 你应该可以在浏览器上打开registry.npmjs.org,它基本上返回一个json。
【解决方案2】:

浏览@Amit K Khanchandani 的所有评论。可能对您的情况有所帮助。

首先卸载 nodejs 和 npm 。 接下来安装两者的最新版本。 比运行 npx create-react-app 项目名称 如果您收到 package.json 文件不存在的错误。 非常重要的一点: "" 比检查您的系统用户名是否包含空格不是问题的原因。 由于用户名中存在空格,您不能使用 cmd npx create-react-app 项目名称。

使用这个命令: npm install -g create-react-app(仅一次) 现在您可以使用 npx create-react-app 项目名称

【讨论】:

    猜你喜欢
    • 2021-07-05
    • 2022-11-21
    • 2018-11-05
    • 2021-04-24
    • 2021-03-03
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多