I have the following code snippet in my app:
import { createBrowserHistory } from 'history';
export default createBrowserHistory({ basename: '/dev' });
This function, and its typings, exist in node_modules
under history
and @types/history
:
export interface BrowserHistoryBuildOptions {
basename?: string;
forceRefresh?: boolean;
getUserConfirmation?: typeof getConfirmation;
keyLength?: number;
}
export default function createBrowserHistory<S = LocationState>(options?: BrowserHistoryBuildOptions): History<S>;
I am now trying to migrate to Yarn 2 with PnP and in that, trying to fix anything yarn dlx @yarnpkg/doctor
finds, as per Yarn's migration tutorial. And the doctor found that this history
is an undeclared dependency.
Undeclared dependency on history
So I yarn add
ed history
and unfortunately, the actual history
library is incopatible with the function we're using in this app (takes window
as an argument, instead of the above options
.
export declare type BrowserHistoryOptions = {
window?: Window;
};
export declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;
I don't really know what I'm looking for here. This usage of ours works well, but Yarn doesn't recognize this as a thing and instead thinks it's an undeclared dependency. But, adding the dependency breaks our function usage. How do I fix this situation?