mac上的react环境搭建
首先看官网的介绍:
Create React App
Create React App 是一个用于学习 React 的舒适环境,也是用 React 创建新的单页应用的最佳方式。
它会配置你的开发环境,以便使你能够使用最新的 JavaScript 特性,提供良好的开发体验,并为生产环境优化你的应用程序。你需要在你的机器上安装 Node >= 8.10 和 npm >= 5.6。要创建项目,请执行:
npx create-react-app my-app
cd my-app
npm start
注意
第一行的
npx
不是拼写错误 —— 它是 npm 5.2+ 附带的 package 运行工具。
使用create-react-app--> 依赖npm --> 依赖Node.js
node.js内置了npm(这也导致要下载npm的话,必须得下载node.js,其包含了npm)
安装node.js
方法1
brew install node

方法2
在官方下载网站下载 pkg 安装包,直接点击安装即可。
安装create react app
npm i -g create-react-app

创建react项目:
create-react-app hello-react
失败了:

更换npm源为国内
npm config set registry http://registry.npm.taobao.org/
速度变快了,socket error没了,但是还是报错

google了下 stackoverflow上有人给了答案:
https://stackoverflow.com/questions/49348482/npm-install-with-error-gyp-failed-with-exit-code-1
If this is a mac machine (OSX) here is what you can do
use terminal
xcode-select --print-path
then remove installed version
sudo rm -r -f /Library/Developer/CommandLineTools
and reinstall
xcode-select --install
that should fix the problem
Ref: gyp: No Xcode or CLT version detected macOS Catalina
后续还是有报错:


一番谷歌应该是缺少包:
brew install giflib cairo libjpeg giflib pixman pkg-config cairo pango libpng jpeg
终于完成
