使用React脚手架创建React项目报错:

报错日志如下:

admindeiMac-3:react_redux albert$ create-react-app hello-react

Creating a new React app in /Users/albert/react_redux/hello-react.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

npm ERR! code 1
npm ERR! path /Users/albert/react_redux/hello-react/node_modules/canvas
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! SOLINK_MODULE(target) Release/canvas-postbuild.node
npm ERR! CXX(target) Release/obj.target/canvas/src/backend/Backend.o
npm ERR! CXX(target) Release/obj.target/canvas/src/backend/ImageBackend.o
npm ERR! CXX(target) Release/obj.target/canvas/src/backend/PdfBackend.o
npm ERR! ../src/backend/Backend.cc:111:10: warning: address of stack memory associated with local variable 'msg' returned [-Wreturn-stack-address]
npm ERR! return msg.c_str();
npm ERR! ^~~
npm ERR! 1 warning generated.
npm ERR! In file included from ../src/backend/PdfBackend.cc:1:
npm ERR! In file included from ../src/backend/PdfBackend.h:4:
npm ERR! ../src/backend/../closure.h:6:10: fatal error: 'jpeglib.h' file not found
npm ERR! #include <jpeglib.h>
npm ERR! ^~~~~~~~~~~
npm ERR! 1 error generated.
npm ERR! make: *** [Release/obj.target/canvas/src/backend/PdfBackend.o] Error 1
npm ERR! gyp ERR! build error
npm ERR! gyp ERR! stack Error: `make` failed with exit code: 2
npm ERR! gyp ERR! stack at ChildProcess.onExit (/Users/albert/react_redux/hello-react/node_modules/node-gyp/lib/build.js:194:23)
npm ERR! gyp ERR! stack at ChildProcess.emit (events.js:315:20)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Darwin 19.6.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/albert/react_redux/hello-react/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/albert/react_redux/hello-react/node_modules/canvas
npm ERR! gyp ERR! node -v v14.16.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/albert/.npm/_logs/2021-03-01T07_57_55_062Z-debug.log

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

Deleting generated file... package.json
Deleting hello-react/ from /Users/albert/react_redux
Done.

解决方法:

brew install pkg-config cairo libpng jpeg giflib