質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
npm

npmは、Node Packaged Modulesの略。Node.jsのライブラリ・パッケージを管理できるツールです。様々なモジュールを簡単にインストールでき、自分でモジュールを作成し公開する際にも使用できます。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

解決済

1回答

1367閲覧

npx create-react-app my-appの後にyarn startをするとエラーが発生する

skytomo

総合スコア35

npm

npmは、Node Packaged Modulesの略。Node.jsのライブラリ・パッケージを管理できるツールです。様々なモジュールを簡単にインストールでき、自分でモジュールを作成し公開する際にも使用できます。

Node.js

Node.jsとはGoogleのV8 JavaScriptエンジンを使用しているサーバーサイドのイベント駆動型プログラムです。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2019/03/23 08:30

前提・実現したいこと

reactのチュートリアルをしようと思いました。
react自体は正直まだよく分からないです。
npx create-react-app my-appをしたあとに、
cd my-appmy-appに移動し、yarn startをしたらエラーが出ました。

発生している問題・エラーメッセージ

チュートリアルの通りにnpx create-react-app my-appをしました。

PS D:\skytomo\Documents\Programming\React> npx create-react-app my-app npx: installed 63 in 18.908s Creating a new React app in D:\skytomo\Documents\Programming\React\my-app. warning You don't appear to have an internet connection. Try the --offline flag to use the cache for registry queries. (node:20600) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. Installing packages. This might take a couple of minutes. Installing react, react-dom, and react-scripts... You appear to be offline. Falling back to the local Yarn cache. yarn add v1.6.0 (node:36648) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. [1/4] Resolving packages... [2/4] Fetching packages... info fsevents@1.2.7: The platform "win32" is incompatible with this module. info "fsevents@1.2.7" is an optional dependency and failed compatibility check. Excluding it from installation. info fsevents@1.2.4: The platform "win32" is incompatible with this module. info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation. [3/4] Linking dependencies... warning "react-scripts > pnp-webpack-plugin > ts-pnp@1.0.1" has unmet peer dependency "typescript@*". [4/4] Building fresh packages... success Saved lockfile. success Saved 6 new dependencies. info Direct dependencies ├─ react-dom@16.8.5 ├─ react-scripts@2.1.8 └─ react@16.8.5 info All dependencies ├─ fork-ts-checker-webpack-plugin@1.0.0-alpha.6 ├─ react-dev-utils@8.0.0 ├─ react-dom@16.8.5 ├─ react-scripts@2.1.8 ├─ react@16.8.5 └─ scheduler@0.13.5 Done in 332.07s. Initialized a git repository. Success! Created my-app at D:\skytomo\Documents\Programming\React\my-app Inside that directory, you can run several commands: yarn start Starts the development server. yarn build Bundles the app into static files for production. yarn test Starts the test runner. yarn 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 yarn start Happy hacking!

npx create-react-app my-appをしたあとに、
cd my-appmy-appに移動し、yarn startをしたらエラーが出ました。

PS D:\skytomo\Documents\Programming\React\my-app> yarn start yarn run v1.6.0 (node:26504) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. $ react-scripts start There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you need to fix locally. The react-scripts package provided by Create React App requires a dependency: "webpack": "4.28.3" Don't try to install it manually: your package manager does it automatically. However, a different version of webpack was detected higher up in the tree: D:\skytomo\node_modules\webpack (version: 4.25.1) Manually installing incompatible versions is known to cause hard-to-debug issues. If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That will permanently disable this message but you might encounter other issues. To fix the dependency tree, try following the steps below in the exact order: 1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder. 2. Delete node_modules in your project folder. 3. Remove "webpack" from dependencies and/or devDependencies in the package.json file in your project folder. 4. Run npm install or yarn, depending on the package manager you use. In most cases, this should be enough to fix the problem. If this has not helped, there are a few other things you can try: 5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead. This may help because npm has known issues with package hoisting which may get resolved in future versions. 6. Check if D:\skytomo\node_modules\webpack is outside your project directory. For example, you might have accidentally installed something in your home folder. 7. Try running npm ls webpack in your project folder. This will tell you which other package (apart from the expected react-scripts) installed webpack. If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That would permanently disable this preflight check in case you want to proceed anyway. P.S. We know this message is long but please read the steps above :-) We hope you find them helpful! error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

試したこと

エラーに書かれている通りに、実行してみました。

  1. yarn.lockを削除しました。(package-lock.jsonmy-appの中にありませんでした。)
  2. node_modulesを削除しました。
  3. webpackmy-appの中にありませんでした。)
  4. yarnを実行しました。そして成功しました。
PS D:\skytomo\Documents\Programming\React\my-app> yarn yarn install v1.6.0 (node:28020) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. [1/4] Resolving packages... success Already up-to-date. Done in 1.05s.

ここで、もう一度yarn startをしましたが、同じエラーが出ました。
5は最初からyarnを使っているので関係ありません。
6は「webpackがプロジェクトディレクトリの外にあるかどうかを確認します。」という意味がよく分からなかったので、飛ばしました。ここのファイルにしか今回ダウンロードしていないので、多分関係ないと思いました。
7を実行したら、下のように出てきました。

PS D:\skytomo\Documents\Programming\React\my-app> npm ls webpack my-app@0.1.0 D:\skytomo\Documents\Programming\React\my-app `-- react-scripts@2.1.8 `-- webpack@4.28.3

それで結局、解決方法が分かりません。
ここからどうすればいいのでしょうか。

ちなみに.envというファイルにSKIP_PREFLIGHT_CHECK=trueを書いたら、動くようになりました。

PS D:\skytomo\Documents\Programming\React\my-app> yarn start yarn run v1.6.0 (node:280) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. $ react-scripts start Starting the development server... Compiled successfully! You can now view my-app in the browser. Local: http://localhost:3000/ On Your Network: http://172.20.10.2:3000/ Note that the development build is not optimized. To create a production build, use yarn build.

が、あまりにも気持ち悪いので、(普通はそうならないはずだから)
原因と解決方法を教えていただきたいです。

補足情報

OS: Windows 10
npm 6.9.0
npx 6.9.0
node v10.15.3
yarn 1.6.0

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

ごめんなさい。
npm startで怒られたときの話|はじめ@休学ラボ|note
npm run build error · Issue #34 · kentcdodds_advanced-react-patterns-v2
に解決方法が書いてありました。
私のググる技術がまだまだだったということですね。
ありがとうございました。

投稿2019/03/23 17:02

skytomo

総合スコア35

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問