【问题标题】:How do you switch from importing objects from tns-core-modules to @nativescript/core?如何从从 tns-core-modules 导入对象切换到 @nativescript/core?
【发布时间】:2021-03-20 23:39:31
【问题描述】:

好的,所以我运行了命令“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

我是不是导入不正确?

【问题讨论】:

    标签: import module nativescript migrate


    【解决方案1】:
    run npm install @nativescript/core
    

    那么这应该可以工作

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

    我用

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

    在我最近的项目中

    【讨论】:

    • 做到了。哇...我发誓我以为我已经安装了它...傻我。当它允许我时,我会在 4 分钟内投票并接受作为答案
    • 如何更改此导入? const { fromObject } = require('tns-core-modules/data/observable')
    • 没有区别使用 import { fromObject } from "@nativescript/core";
    猜你喜欢
    • 1970-01-01
    • 2021-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    相关资源
    最近更新 更多