首页 > 解决方案 > 升级 Nativescript 插件时缺少参考(tns-core-modules → @nativescript/core 迁移)

问题描述

我正在更新现有插件,以使其与即将发布的 nativescript 版本兼容。

对包的所有引用tns-core-modules都已替换为@nativescript/core.

发布的文档说新库应该与旧版本兼容。不幸的是,在这种情况下,某些东西肯定发生了变化(与视图生命周期有关),并且插件不是 100% 工作的。

这就是为什么我尝试完全迁移它的依赖项,但是由于一些错误,构建过程是不可能的:

node_modules/@nativescript/core/ui/frame/index.d.ts:494:38 - error TS2304: Cannot find name 'ModuleContext'.

494 export function reloadPage(context?: ModuleContext): void;

...

map-view.ios.ts:80:40 - error TS2304: Cannot find name 'WeakRef'.

80     public static initWithOwner(owner: WeakRef<MapView>): MapViewDelegateImpl {
node_modules/@nativescript/core/ui/styling/style/index.d.ts:31:39 - error TS2304: Cannot find name 'WeakRef'.

31     constructor(ownerView: ViewBase | WeakRef<ViewBase>);

我可以通过skipLibCheck: true在 tsconfig.json 中设置来构建插件。它使插件编译,但问题稍后在运行时出现。所以必须解决才能完成迁移。

有什么提示吗?

谢谢!

标签: nativescriptnativescript-plugin

解决方案


也许这不是 100% 推荐的解决方案,但如果您确实遇到同样的问题,请将此行添加到您的 tsconfig.json:

        "types": [
            "@nativescript/core",
        ],

推荐阅读