首页 > 解决方案 > 纱线无法识别内置包?

问题描述

我的应用程序中有以下代码片段:

import { createBrowserHistory } from 'history';

export default createBrowserHistory({ basename: '/dev' });

此函数及其类型存在于node_modulesunderhistory和中@types/history

export interface BrowserHistoryBuildOptions {
    basename?: string;
    forceRefresh?: boolean;
    getUserConfirmation?: typeof getConfirmation;
    keyLength?: number;
}

export default function createBrowserHistory<S = LocationState>(options?: BrowserHistoryBuildOptions): History<S>;

我现在正在尝试使用 PnP 迁移到 Yarn 2,并yarn dlx @yarnpkg/doctor根据 Yarn 的迁移教程尝试修复任何发现。并且医生发现这history是一个未声明的依赖。

Undeclared dependency on history

所以我yarn add编辑history了,不幸的history是,实际的库与我们在这个应用程序中使用的函数不兼容(window作为参数,而不是上面的options.

export declare type BrowserHistoryOptions = {
    window?: Window;
};
export declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;

我真的不知道我在这里寻找什么。我们的这种用法效果很好,但 Yarn 并不认为这是一个东西,而是认为它是一个未声明的依赖项。但是,添加依赖会破坏我们的函数使用。我该如何解决这种情况?

标签: yarnpkgdependency-managementhistory.jsyarnpkg-v2

解决方案


推荐阅读