create-react-appができなかった話


はじめに

Reactでもやってみようかと試したところエラーが出ました。
その内容と解決法についてです。

どこでエラーが発生したのか

npm install -g create-react-app

は成功

create-react-app my-app

でエラー

エラー内容は

error A:\work\my-app\node_modules\ejs: Command failed.
Exit code: 1
Command: node ./postinstall.js
Arguments:
Directory: A:\work\my-app\node_modules\ejs


Aborting installation.
  yarnpkg add --exact react react-dom react-scripts cra-template --cwd A:\work\practice\react-practice\my-app has failed.

Deleting generated file... package.json
Deleting generated file... yarn.lock
Deleting generated file... node_modules
Deleting my-app/ from A:\work\
Done.

だそう

解決策

nodejs, npmのアップデートしてもエラー

そして、create-react-appはyarnでreactなどをインストールしてるらしいです。
ふと「そういえば前からyarnでインストールできないものあったな」と思い出しました。

そこで

create-react-app my-app --use-npm

としてみると

Success! Created my-app at A:\work\my-app
Inside that directory, you can run several commands:

  npm start
    Starts the development server.

  npm run build
    Bundles the app into static files for production.

  npm test
    Starts the test runner.

  npm run eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd my-app
  npm start

Happy hacking!


でけた