【问题标题】:nativescript-carousel error with tns-platform-declarations带有 tns-platform-declarations 的 nativescript-carousel 错误
【发布时间】:2019-03-05 22:18:14
【问题描述】:

我正在使用 nativescript-carousel 插件构建一个 nativescript 轮播,但是当我执行 tns build android 时出现此错误:

node_modules/nativescript-carousel/index.d.ts(1,22): error TS6053: File 'D:/Documents/coursera_examples/nativescript/VilcabambaHotel/node_modules/nativescript-carousel/node_modules/tns-platform-declarations/没有找到 android.d.ts'。

我的 home.component.html 轮播是这样的:

    <GridLayout  horizontalAlignment="center" verticalAlignment="top" rows="*" columns="*" height="95%">        
    <Carousel #carousel ios:indicatorOffset="0,-10" ios:finite="true" ios:bounce="false" showIndicator="true" height="100%" indicatorAnimation="SWAP"
        indicatorColor="#66ccff" indicatorColorUnselected="#cceeff" height="250" width="80%">
        <CarouselItem backgroundColor="white" height="100%">
            <GridLayout *ngIf="cabin">
                <Image  [src]="BaseURL + cabin.image" ></Image>
            </GridLayout>
        </CarouselItem>
        <CarouselItem backgroundColor="white">
           <GridLayout *ngIf="house">
                <Image  [src]="BaseURL + house.image" ></Image>
            </GridLayout>
        </CarouselItem>
        <CarouselItem backgroundColor="white">
           <GridLayout *ngIf="ecoactivity">
                <Image  [src]="BaseURL + ecoactivity.image" ></Image>
            </GridLayout>
        </CarouselItem>
    </Carousel>
    </GridLayout>

这是我的 home.component.ts

import { Component, OnInit, Inject, ChangeDetectorRef } from '@angular/core';

//import { TNSFontIconService } from 'nativescript-ngx-fonticon';
import { Page } from "ui/page";
import { View } from "ui/core/view";
import { SwipeGestureEventData, SwipeDirection } from "ui/gestures";
import * as enums from "ui/enums";

import { Cabin } from '../shared/cabin';
import { CabinService } from '../services/cabin.service';
import { House } from '../shared/house';
import { HouseService } from '../services/house.service';
import { Ecoactivity } from '../shared/ecoactivity';
import { EcoactivityService } from '../services/ecoactivity.service';
import { DrawerPage } from '../shared/drawer/drawer.page';



import { registerElement } from 'nativescript-angular/element-registry';
import { Carousel, CarouselItem } from 'nativescript-carousel';

registerElement('Carousel', () => Carousel);
registerElement('CarouselItem', () => CarouselItem);

@Component({
    selector: 'app-home',
    moduleId: module.id,
    templateUrl: './home.component.html',
    // styleUrls: ['./home.component.css']
})
export class HomeComponent extends DrawerPage implements OnInit {

    cabin: Cabin;
    house: House;
    ecoactivity: Ecoactivity;
    cabinErrMess: string;
    houseErrMess: string;
    ecoactivityErrMess: string;


    constructor(private cabinservice: CabinService,
        private houseservice: HouseService,
        private ecoactivityservice: EcoactivityService,
        private changeDetectorRef: ChangeDetectorRef,
        private page: Page,
       // private fonticon: TNSFontIconService,
        @Inject('BaseURL') private BaseURL) {
        super(changeDetectorRef);
    }

    ngOnInit() {
        this.cabinservice.getFeaturedCabin()
            .subscribe(cabin => this.cabin = cabin,
                errmess => this.cabinErrMess = <any>errmess);
        this.houseservice.getFeaturedHouse()
            .subscribe(house => this.house = house,
                errmess => this.houseErrMess = <any>errmess);
        this.ecoactivityservice.getFeaturedEcoactivity()
            .subscribe(ecoactivity => this.ecoactivity = ecoactivity,
                errmess => this.ecoactivityErrMess = <any>errmess);

    }

如果我删除下一行代码但我的轮播停止工作,错误就会消失

从 'nativescript-angular/element-registry' 导入 { registerElement }; 导入 { Carousel, CarouselItem } from 'nativescript-carousel';

registerElement('轮播', () => 轮播); registerElement('CarouselItem', () => CarouselItem

我用下一行代码创建了一个名为 reference.d.ts 的文档,但错误仍然存​​在。

/// <reference path="./node_modules/tns-platform-declarations/ios.d.ts" />
/// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />

【问题讨论】:

    标签: android angular typescript nativescript


    【解决方案1】:

    看起来插件内声明使用不当,您可以通过更新路径来手动调整它

    /// <reference path="../tns-platform-declarations/android.d.ts" />
    

    来自

    /// <reference path="./node_modules/tns-platform-declarations/android.d.ts" />
    

    在index.d.ts

    编辑:

    如果您仍然发现任何其他 TS 错误,您可以在 compilerOptions 中添加 "skipLibCheck": true tsconfig.json。

    【讨论】:

    • 我尝试将此添加到我的 inde.d.ts 运行 tns build android 并仍然得到相同的错误。如果我删除我的 reference.d.ts 文件,我会得到相同的错误以及以下 3 个错误:node_modules/nativescript-carousel/index.d.ts(45,54): error TS2304: Cannot find name 'android'。 node_modules/nativescript-carousel/index.d.ts(53,16):错误 TS2503:找不到命名空间“android”。 node_modules/nativescript-carousel/index.d.ts(56,51):错误 TS2304:找不到名称“android”。
    • 你尝试过干净的构建吗?
    • 是的,我有。我已经完成了 tns 平台删除 android 然后 tns 平台添加了 android,删除了我的 node_modules 和钩子并做了 npm 安装
    • 如果您删除 node_modules,那么您将丢失上面所做的更改。修改以上行后删除platforms文件夹就可以了。
    • 我在删除 node_modules 后添加了更改。我尝试在重新安装 node_ 模块并添加上面的行后进行干净的构建,但仍然得到相同的错误
    猜你喜欢
    • 2017-04-03
    • 1970-01-01
    • 1970-01-01
    • 2019-04-19
    • 2016-10-09
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多