LoginSignup
0
0

More than 1 year has passed since last update.

【React】create-react-app時のNeed to install the following packages: create-react-appを出力させない方法【Docker】

Last updated at Posted at 2022-04-07

はじめに

 本記事は、プログラミング初学者が学習を進めていて疑問に思った点について調べた結果を備忘録も兼ねてまとめたものです。
 そのため、記事の内容に誤りが含まれている可能性があります。ご容赦ください。
 間違いを見つけた方は、お手数ですが、ご指摘いただけますと幸いです。

create-react-app時のNeed to install the following packages: create-react-appを表示させない方法

状況

npx create-react-app myapp実行時に以下のように Need to install the following packages: create-react-app Ok to proceed? (y)というメッセージが出力され、yを入力してEnterを押さないと処理が継続されません。
Dockerを使用する際にdocker compose run --rm front sh -c "npx create-react-app myapp"を実行するとbuildの処理の後にこのメッセージが表示され一度処理が止まるため改善できないか調べました。

ターミナル
$ docker compose run --rm front sh -c "npx create-react-app myapp --template typescript"
[+] Running 1/0
 ⠿ Network react-test_default  Created                                                                                       0.0s
[+] Building 92.4s (8/8) FINISHED
  <以下略>
                                                                
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

Need to install the following packages:
  create-react-app
Ok to proceed? (y) y

Creating a new React app in /myapp/front.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template-typescript...
  <以下略>

改善方法

npx -y create-react-app myappのように-yオプションを使用することで出力しないようにすることができました。

ターミナル
$ docker compose run --rm front sh -c "npx -y create-react-app myapp --template typescript"
[+] Running 1/0
 ⠿ Network react-test_default  Created                                                                                       0.0s
[+] Building 92.4s (8/8) FINISHED
  <以下略>
                                                                
Use 'docker scan' to run Snyk tests against images to find vulnerabilities and learn how to fix them

Creating a new React app in /myapp/front.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template-typescript...
  <以下略>

-yオプションについては以下に記載されています。

To prevent security and user-experience problems from mistyping package names, npx prompts before installing anything. Suppress this prompt with the -y or --yes option.

Need to install the following packages: create-react-app Ok to proceed? (y)の役割は上記の通りですので、-yオプションを使用する際には、入力ミスにご注意ください。

pのドキュメントでも、以前にnpm install -g create-react-appしている場合には、npm uninstall -g create-react-app等でアンインストールすることが推奨されていました。

サポートされていないことがわかったエラー文
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

If you've previously installed create-react-app globally via npm install -g create-react-app, we recommend you uninstall the package using npm uninstall -g create-react-app or yarn global remove create-react-app to ensure that npx always uses the latest version.

0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0