web-dev-qa-db-ja.com

Reactアプリでnpm startを実行するときのbabel-jest依存関係の問題

私がしているのは、create-react-appを実行し、アプリにcdしてからnpm/yarn start。次のエラー/出力/ログが表示されます。提案されたすべての手順を説明しました。唯一機能するのは、Yarnとnpmの両方の最後の手段としての.envのSKIP_PREFLIGHT_CHECK = trueです。最近、Mojaveにアップデートしましたが、同様の経験がある場合はXcodeを再インストールする必要がありました。

画像が十分でない場合は、以下の出力を貼り付けました。

事前にご協力いただきありがとうございます...ジェイソン

コンソールのスクリーンショット screenshot

Last login: Tue Oct 30 16:30:24 on ttys002
TheLAB11:~ jasonspiller$ cd repos/react-express-graphql-app/
TheLAB11:react-express-graphql-app jasonspiller$ npm start

> [email protected] start /Users/jasonspiller/repos/react-express-graphql-app
> 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:

  "babel-jest": "23.6.0"

Don't try to install it manually: your package manager does it automatically.
However, a different version of babel-jest was detected higher up in the tree:

  /Users/jasonspiller/node_modules/babel-jest (version: 23.4.2) 

Manually installing incompatible versions is known to cause hard-to-debug issues.

If 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 "babel-jest" 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 /Users/jasonspiller/node_modules/babel-jest is outside your project directory.
     For example, you might have accidentally installed something in your home folder.

  7. Try running npm ls babel-jest in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed babel-jest.

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!

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/jasonspiller/.npm/_logs/2018-10-30T23_09_42_358Z-debug.log
12
jasonspiller

私はちょうど同じ問題を抱えていました。何らかの理由で、パッケージは私のホームディレクトリのnode_modulesディレクトリに置かれました。また、jestパッケージでもまったく同じエラーが発生しました。

npm uninstall -g babel-jestyarn global remove babel-jestは何もしないので、これを修正するcorrect方法がわかりません。

問題の原因となっているフォルダーを吹き飛ばして修正しました:bash rm -rf ~/node_modules/babel-jest ~/node_modules/jest

それらのパッケージがそこでどのように終わり、それらを削除する適切な方法を知ることは素晴らしいことですが、現時点では、プリフライトチェックをスキップせずにCRA devサーバーを実行するにはフォルダーを削除するだけで十分です。

14
Wade J

この問題は、アプリケーションを実行するフォルダーの親ディレクトリにnode_modulesがある場合に発生する可能性があります。 node_modulesディレクトリを削除することで問題を解決しました。

12
Ahmet Şimşek

この問題はcreate-react-app 3.0.0で再発したようです。

The react-scripts package provided by Create React App requires a dependency:

  "babel-jest": "24.7.1"

https://github.com/facebook/create-react-app/issues/6756#issuecomment-489562571で指摘したように、パッケージにバージョン解像度を追加する.jsonは問題を一時的に修正します

"resolutions": {
  "babel-jest": "24.7.1"
},

更新:create-react-app 3.0.1 で修正されました。 アップグレードがオプションの場合、実行できます

npm install --save --save-exact [email protected]

または

yarn add --exact [email protected]
11
Martin Fahl

私も同様の問題に直面し、以下の手順に従って問題を解決することができました。

  1. プロジェクトのルートディレクトリに.envファイルを作成し、次のステートメントを追加します

SKIP_PREFLIGHT_CHECK = true

  1. ファイルを保存する

  2. Node_modules、yarn.lock、package.lockを削除します

  3. 次に、node_modulesを再インストールします

npmインストール

これは動作するはずです

2
Rajesh Samson
  1. 実行:npm ls babel-jest

got:[email protected]および[email protected]がインストールされています

これは、差分バージョンでtow babel-jestをインストールすることを意味します

  1. 実行:npm uninstall [email protected].問題を修正
2
leaez

私はこの問題を抱え、最終的に簡単に解決しました。おそらくご存知のように、create-react-appを使用すると、Jestはデフォルトで設定され、Jestをインストールする必要はありません(Webpackを使用する場合、Jestをインストールできます)。したがって、Create-react-appを使用して、誤ってJestをインストールした場合:

  1. まずアンインストールします(使用する場合:(npm install --save-dev jest)、jestをPackage.jsonから直接削除するか、使用することを忘れないでください:(npm uninstall --save-dev jest
  2. Package-lock.jsonを削除します(package.jsonではありません)
  3. Node_modulesを削除します
  4. npm install

これでエラーは表示されず、簡単に使用できます:(npm start)または(npm test)

また、次のツールをインストールして、テストをReactコンポーネント:(npm install --save-dev enzyme enzyme-adapter-react-16 jest-enzyme)]にインストールし、jestと酵素を使用してテストを作成したことにも言及しておく必要があります。 :(npm test

幸運を!

2
Nasser

OKすべてを試した後、最終的に解決策を見つけました。最終的に機能したのは次のとおりです。

  • まず、cmdのエラーメッセージを最初から読みます。どのモジュールが問題を引き起こしているかを教えてくれます。コンピュータに古いバージョンがインストールされている可能性があります。例:babel-jestバージョン2.4.4
  • Node.jsフォルダーc:/ Users /(your user)/ node_modulesに移動し、そのモジュールを見つけて削除します。
  • Cmdに戻り、npm startを実行します。同じエラーが発生する場合があります。ただし、別のモジュール用です。同じ方法で削除し、実行されるまで繰り返します。
1
Ali Alsabe

同じ問題が発生したため、この問題を修正しました。私のローカルのnode_modulesのため、何らかの理由で。 babel-jestとjestを削除しました。その後、npmが起動します。これが間違って解決したかどうかはわかりませんが、これは正しいです。

0
Blue Tram

私はまったく同じ問題を抱えていました。私が試みたのは、node_modulesフォルダーのあるディレクトリの外部に反応アプリを作成することでした。その後、糸のスタートでアプリを起動しましたが、もうエラーはありませんでした。

0
morenotos