为什么 React-Create-App 无法读取 ReactRouter 数据类型?

Why React-Create-App fails to read ReactRouter data type?

我目前正在尝试构建一个 React-Create-App。它是 github 上可用的软件包 - 8 天前的最新提交。

我的编译器无法翻译我的 ReactRouters 代码。

这是我的 App.js 代码,首先编辑:

import React, { Component } from 'react';
import './App.css';
import { BrowserRouter as Router, Route, Link} from 'react-router-dom';


class App extends Component {
  render() {
    return (

      <Router>
           <div className="App">
              <Route path='/' render={
                  ()=> {
                    return (<h1> Welcome Home </h1> ) ;

                  }

              }/>
           </div>
     </Router>
    );
  }
} 


export default App;

错误日志如下:

Failed to compile.

Error in ./src/App.js Module not found: 'react-router-dom' in [current folder]

@ ./src/App.js 16:22-49

但是当我弹出我的 ReactCreateApp 时,我在包 JSON:

中有效地看到了一个 react-router-dom

我该如何解决这个问题?

我在 codesandbox 中试过了,效果很好。看看这里。 https://codesandbox.io/s/7o3qjyy6

试试 npm 安装?

EDIT

这次我创建了一个没有codesandbox的应用程序。

npx create-react-app my-app
cd my-app/

在 package.json 中添加了一行,因为 create-react-app 本身说要在此处添加这样的路由器:https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-a-router

"react-router-dom": "^4.2.2"

做过

npm i

它奏效了。