Module not found Error: Can't resolve 'history' in @types/history

Module not found Error: Can't resolve 'history' in @types/history

正在开发一个 React 应用程序,我想在其中使用 @types/history 模块..

已安装

npm install --save @types/history

并且在我的组件文件中尝试导入

import { createBrowserHistory, History } from 'history' 

import { createBrowserHistory, History } from '@types/history'

但是抛出异常

Module not found: Can't resolve 'history' in

提前致谢。

安装@types/history 时,您只是为打字稿编译器提供有关 history 包的类型信息。不是包裹本身。有关详细信息,请参阅此 示例。

因此 - 您必须安装 history 软件包才能使用它:

$ npm install --save history

github rep.

上查看有关其用法的更多信息

尝试使用 npm

安装 history 和 react 路由器 dom 包
npm install --save history
npm install react-router-dom --save