You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

报错:'Action'未从'history'导出,未导入Action却出现该问题求助

Fix: 'Action' is not exported from 'history' Error After Downgrading History Package

Let's break down what's going on here and how to fix this frustrating error:

Why This Error Occurs

The 'Action' is not exported from 'history' issue stems from a version mismatch between react-router-dom and the history package you installed after rolling back.

Action is a type introduced in newer versions of the history library—it's used to describe navigation actions like POP, PUSH, or REPLACE. When you downgraded history to an older version, that version doesn't include the Action export, but your current react-router-dom version relies on it to function properly.

Step-by-Step Solutions

1. Install a history version compatible with your react-router-dom

First, check your package.json to confirm which version of react-router-dom you're using:

  • If you're on react-router-dom@5.x, you need history@4.x (e.g., history@4.10.1 is a reliable compatible version)
  • If you're on react-router-dom@6.x, you need history@5.x

Run these commands to align the versions:

# Uninstall the mismatched history version
npm uninstall history

# Install the compatible version (replace with the one matching your react-router-dom)
npm install history@4.10.1

2. Let your package manager handle dependencies (recommended)

Skip manually specifying the history version entirely—remove it from your package.json, then run:

npm install

This will let npm automatically install the exact history version that your react-router-dom depends on, eliminating version conflicts for good.

Quick Code Improvement

Looking at your App component, you're using the base Router from react-router-dom. In most cases, you should use BrowserRouter instead (it handles the browser's history API automatically). Swap it out like this:

// Replace this import:
import { Router, Switch, Route } from 'react-router-dom';

// With this:
import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';

This avoids needing to manually create and pass a history instance, which can prevent additional version-related headaches.

内容的提问来源于stack exchange,提问作者Salil Rajkarnikar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 16:32:48