如何从将对象从tns-core-modules导入到@ nativescript/core? [英] How do you switch from importing objects from tns-core-modules to @nativescript/core?
问题描述
好的,因此我在命令行中运行了命令"ns migration"使用较新版本的nativescript.这样做是除去tns-core-modules依赖关系,这意味着我无法再使用它来导入内容.假设我们应该改用@ nativescript/core,但是问题是当我尝试导入对象时@ nativescript/core无法正常工作,并且遇到找不到模块'@ nativescript/core"或其相应的类型声明".
Okay, so I ran the command "ns migrate" to use a newer version of nativescript. What this does is remove the tns-core-modules dependency, which means I can't use it to import things anymore. Supposedly we're supposed to use @nativescript/core instead, but the problem is when I try to import objects @nativescript/core doesn't work and I'm greeted with "cannot find module '@nativescript/core' or its corresponding type declarations".
例如,这将不起作用:
import { Label } from "@nativescript/core";
但是有了tns-core-modules依赖,它可以工作并且很简单:
But with the tns-core-modules dependency it worked and was as simple as:
import { Label } from "tns-core-modules/ui/label"
运行ns migration命令后,它将删除tns-core-modules并将@ nativescript/core更新为7.3.0
After running the ns migrate command it remove tns-core-modules and updates @nativescript/core to 7.3.0
我导入不正确吗?
推荐答案
run npm install @nativescript/core
然后这应该工作
import { Label } from "@nativescript/core";
我用
import { ApplicationSettings, ImageSource } from '@nativescript/core';
在我最近的项目中
这篇关于如何从将对象从tns-core-modules导入到@ nativescript/core?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!