你如何从从 tns-core-modules 导入对象切换到 @nativescript/core?

问题描述

好的,所以我运行命令“ns migrate”以使用较新版本的 nativescript。这样做是删除 tns-core-modules 依赖项,这意味着我不能再使用它来导入东西。据说我们应该改用@nativescript/core,但问题是当我尝试导入对象时 @nativescript/core 不起作用,我收到“找不到模块‘@nativescript/core’或其相应的类型声明”。

例如,这将不起作用:

import { Label } from "@nativescript/core";

但是有了 tns-core-modules 依赖项,它就可以工作并且非常简单:

import { Label } from "tns-core-modules/ui/label"

运行 ns migrate 命令后,它会删除 tns-core-modules 并将 @nativescript/core 更新为 7.3.0

我的导入有误吗??

解决方法

run npm install @nativescript/core

那么这应该可行

import { Label } from "@nativescript/core";

我用

import { ApplicationSettings,ImageSource } from '@nativescript/core';

在我最近的项目中