Do I need to install React before I install react-bootstrap

纵然是瞬间 提交于 2019-12-13 06:14:21

问题


I am trying to install react-bootstrap. When I run the command

npm install react-bootstrap --save

I get the following (some path names replaced with '...') :

npm WARN saveError ENOENT: no such file or directory, open '/Users/../package.json'/Users/.../..

├── UNMET PEER DEPENDENCY react@>=0.14.0  
├─┬ react-bootstrap@0.30.7  
│ ├─┬ babel-runtime@6.20.0   
│ │ ├── core-js@2.4.1   
│ │ └── regenerator-runtime@0.10.1   
│ ├── classnames@2.2.5   
│ ├── dom-helpers@2.4.0   
│ ├─┬ invariant@2.2.2   
│ │ └─┬ loose-envify@1.3.0   
│ │   └── js-tokens@2.0.0   
│ ├── keycode@2.1.8   
│ ├── UNMET PEER DEPENDENCY react@>=0.14.0  
│ ├── UNMET PEER DEPENDENCY react-dom@>=0.14.0  
│ ├─┬ react-overlays@0.6.10   
│ │ └── UNMET PEER DEPENDENCY react@>=0.14.0  
│ ├── react-prop-types@0.4.0   
│ ├── uncontrollable@4.0.3   
│ └── warning@3.0.0   
└── UNMET PEER DEPENDENCY react-dom@>=0.14.0  

npm WARN enoent ENOENT: no such file or directory, open '/Users/../../package.json'  
npm WARN react-bootstrap@0.30.7 requires a peer of react@>=0.14.0 but none was installed.  
npm WARN react-bootstrap@0.30.7 requires a peer of react-dom@>=0.14.0 but none was installed.  
npm WARN react-overlays@0.6.10 requires a peer of react@>=0.14.0 but none was installed.  
npm WARN react-overlays@0.6.10 requires a peer of react-dom@>=0.14.0 but none was installed.  
npm WARN uncontrollable@4.0.3 requires a peer of react@>=0.11.0 but none was installed.  
npm WARN react-prop-types@0.4.0 requires a peer of react@>=0.14.0 but none was installed.  

Do I need to install React before I install react-bootstrap? I don't see any specific mention of it in the doc. (I am new to React and didn't even know that I need React also if I am using react-bootstrap. I thought it included React as well. But saw this mentioned in the Javascript section of the same doc later: "If you have React setup and React-Bootstrap installed you have everything you need.")


回答1:


In the React ecosystem, you should always install react + react-dom first. Don't rely on peer dependencies in general.




回答2:


Yes you will need to install react and react-dom separately. A peer dependency is one that the package you're installing assumes to already be installed.

The behaviour changed in npm 3 to simply warn of those that are missing.

npm install react react-dom react-bootstrap --save



来源:https://stackoverflow.com/questions/41299783/do-i-need-to-install-react-before-i-install-react-bootstrap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!