前提・実現したいこと
npx create-react-appをターミナル上で実行し、Reactを使用できるフォルダーを作りたい。
発生している問題・エラーメッセージ
フォルダー自体を作ることができない
You are running `create-react-app` 4.0.3, which is behind the latest release (5.0.0). We no longer support global installation of Create React App. Please remove any global installs with one of the following commands: - npm uninstall -g create-react-app - yarn global remove create-react-app
試したこと
- npm uninstall -g create-react-app
そもそもグローバルにはcreate-react-appは存在しないようです。
npm ERR! code EACCES npm ERR! syscall rename <省略> npm ERR! errno -13 npm ERR! Your cache folder contains root-owned files, due to a bug in npm ERR! previous versions of npm which has since been addressed // こちらを叩いてもダメでした。 npm ERR! To permanently fix this problem, please run: npm ERR! sudo chown -R 501:20 "/Users/[自分の名前]/.npm"
- npx clear-npx-cache
補足情報(FW/ツールのバージョンなど)
- mac
- npm -v
8.3.1 - node -v
v16.14.0
追記
エラー文の下の方に
npm ERR! A complete log of this run can be found in: npm ERR! /Users/[自分の名前]/.npm/_logs/2022-03-05T22_05_16_550Z-debug-0.log
という表記があるので中身をみたところ、
314 error path /Users/[自分の名前]/.npm-global/lib/node_modules/create-react-app 315 error errno -13 316 verbose Error: EACCES: permission denied, mkdir '/Users/[自分の名前]/.npm-global/lib/node_modules/create-react-app' 317 error 317 error Your cache folder contains root-owned files, due to a bug in 317 error previous versions of npm which has since been addressed.
という表記を見つけましたのでこちらの記事の解決方法1を参考にして
sudo chmod 777 /Users/[自分の名前]/.npm-global/lib sudo chmod 777 /Users/[自分の名前]/.npm-global/lib/node_modules
また上記と同じような
422 verbose Error: EACCES: permission denied, symlink '../lib/node_modules/create-react-app/index.js' -> '/Users/[自分の名前]/.npm-global/bin/create-react-app'
というエラーが出たので
sudo chmod 777 /Users/[自分の名前]/.npm-global/bin/create-react-app
をやってみましたが今度は別の
EACCES: permission denied, rename '/Users/[自分の名前]/.npm-global/lib/node_modules/npm' -> '/Users/kitajimashihomi/.npm-global/lib/node_modules/.npm-N9ngGUni'
が出てきました。そもそも/Users/kitajimashihomi/.npm-global/lib/node_modulesには権限を与えたのにこのパス以下のファイル、ディレクトリには権限が与えられていないのでしょうか?
この後npx clear-npx-cache,をして npx create-react-app@5.0.0を実行してもエラーメッセージは変わらずです。
node はどうやって入れてますか?
自分は homebrew で入れた node v17.6.0 と npm 8.5.1 (と yarn 1.22.17) ですが、
・npm install -g create-react-app して create-react-app
・npm uninstall -g create-react-app して npx create-react-app
・yarn create react-app
どれも成功しますけど…。
私もhomebrewで入れました!
homebrew で入れた場合、基本的にユーザー権限で入るので sudo する必要はないんですが、ネットの記事を鵜呑みにして sudo npm install -g 〜 とかしちゃったんでしょうね…。
また、homebrew で入れた場合、定期的に brew update および brew upgrade で更新することが推奨されてます。
(homebrew の入れ方の記事はたくさんあるけど、その先のことまで書いてある記事は少なくて、困ったものです…。)
まさに sudo npm install -g をやっちゃいました。。。
もうどうすれば良いのかわからないです。原因がわかっただけでもよかったです。

回答2件
あなたの回答
tips
プレビュー