npm npx create-react-app导致错误的项目名称

rxztt3cl  于 2022-11-14  发布在  React
关注(0)|答案(3)|浏览(165)

我正在使用第一个命令创建一个react应用程序; 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.

调试日志文件

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 ]
xtupzzrd

xtupzzrd1#

也许你在某个代理后面,
试试这个
进入设置〉网络和互联网〉代理服务器,然后关闭自动检测设置下的自动代理服务器设置在Windows上。然后它应该工作正常

whlutmcx

whlutmcx2#

浏览一下@Amit K Khanchandani的所有评论。可能对你的情况有帮助。
首先卸载nodejs和npm。接下来安装两者的最新版本。然后运行npx create-react-app projectname,如果你得到package.json文件不存在的错误。非常重要的一点:““然后检查您的系统用户名,如果它包含空格,那么它是问题的原因。因为空格出现在用户名中,您不能使用cmd npx create-react-app projectname。
请使用以下命令:npm install -g create-react-app(仅一次)现在您可以使用npx create-react-app项目名称创建项目

p5cysglq

p5cysglq3#

如果您在Linux上使用Snap安装了Node,我通过使用Snap卸载Nodejs解决了这个问题

sudo snap remove node

使用apt重新安装。

sudo apt install nodejs npm

相关问题