1. 创建react项目(create-react-app demo01)时出现错误:
error An unexpected error occurred: "https://registry.yarnpkg.com/react: connect ETIMEDOUT
删除目录:C:\Users\<login user>\AppData\Roaming\npm\node_modules\yarn ,再重试(create-react-app demo01)即可。
2.解决1后,创建react项目时还出现了链接超时的问题,或卡住不动的问题,这是因为react的仓库在国外,而……
解决办法如下:
使用国内仓库:npm install -g cnpm --registry=https://registry.npm.taobao.org
修改create-react-app使用cnpm:编辑C:\Users\<login user>\AppData\Roaming\npm\node_modules\create-react-app\createReactApp.js ,把下面几个地方的npm改我cnpm:
command = 'npm'; --> command = 'cnpm';
npmVersion = execSync('npm --version') --> npmVersion = execSync('cnpm --version')
let httpsProxy = execSync('npm config get https-proxy') --> let httpsProxy = execSync('cnpm config get https-proxy')
childOutput = spawn.sync('npm', ['config', 'list']).output.join(''); --> childOutput = spawn.sync('cnpm', ['config', 'list']).output.join('');
再重试(create-react-app demo01)即可。