簡體   English   中英

使用 Storybook 創建 React App 創建 webpack 問題

[英]Create React App with Storybook creating webpack issue

所以我創建了一個大型 React 應用程序,並使用 Create React App 進行設置。 最近我們開始使用 Storybook 來處理和創建組件。 它很棒。 然而,當我們嘗試運行或構建應用程序時,我們不斷遇到這個奇怪的 webpack 問題。 這是控制台注銷:

> 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.41.2"

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:

  /Users/alexanderkaran/Documents/ClimateClever/cc_school_web/node_modules/webpack (version: 4.41.5) 

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 /Users/alexanderkaran/Documents/ClimateClever/cc_school_web/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!

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cc_school_web@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cc_school_web@0.1.0 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/alexanderkaran/.npm/_logs/2020-01-23T05_20_16_003Z-debug.log
alexanderkaran@AlexandersMBP2 cc_school_web % 

我知道你的想法你一定安裝了 webpack,我沒有。 當我運行時:

npm ls webpack 

我得到這個注銷:

cc_school_web@0.1.0 /Users/alexanderkaran/Documents/ClimateClever/cc_school_web
├─┬ @storybook/react@5.3.8
│ ├─┬ @storybook/core@5.3.8
│ │ ├─┬ corejs-upgrade-webpack-plugin@2.2.0
│ │ │ └── webpack@4.41.5  deduped
│ │ └── webpack@4.41.5  deduped
│ └── webpack@4.41.5 
└─┬ react-scripts@3.3.0
  └── webpack@4.41.2 

alexanderkaran@AlexandersMBP2 cc_school_web % 

所以這個問題似乎與故事書有關。 如果我卸載所有 npm 模塊並刪除故事書,然后重新添加所有內容,但最終它會中斷。

有沒有人解決這個問題? 或者我錯過了什么?

看起來這是一個問題,Webpack Create React App 使用的版本比 Storybook 有時使用的版本落后幾步。

沒有修復,但有一些解決方法。

您可以在此處找到有關該問題的更多信息:

https://github.com/storybookjs/storybook/issues/6505

一種解決方法是將 SKIP_PREFLIGHT_CHECK=true 添加到項目中的 .env 文件中。

但這可能會導致問題。

另一種解決方法是繼續使用故事書的某個版本並創建可相互協作且不會導致這些問題的 React 應用程序。 因此,如果 Storybook 包含 Webpack 版本升級,請不要直接升級它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM