【问题标题】:Cytoscape with Angular and Typesript error TS2305: Module has no default export带有 Angular 和 Typesript 错误 TS2305 的 Cytoscape:模块没有默认导出
【发布时间】:2022-04-13 06:23:36
【问题描述】:

我在 Angular 中有一个应用程序,我尝试使用 Cytoscape。我使用 npm 安装 Cystoscape 和 Types/cytoscape 以使用,但是当我导入一个错误时。 我开始一个新项目只是为了在我的应用上实施之前进行测试。

我的 app.module

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';
import { GraphComponent } from './graphCytoscape/graph.component';
import cytoscape = require('cytoscape');


@NgModule({
  declarations: [
    AppComponent,
    GraphComponent,
  ],
  imports: [
    BrowserModule,
  ],
  exports: [],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

我的组件:

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

@Component({
    selector: 'app-graph',
    templateUrl: 'graph.component.html'
})

export class GraphComponent implements OnInit {
    cy;
    constructor() { }

    ngOnInit() {
        this.cy = cytoscape({
             container: document.getElementById('cy'),
             elements: [
                { data: { id: 'a' } },
                { data: { id: 'b' } },
                { data: {
                    id: {
                        id: 'ab',
                        source: 'a',
                        target: 'b',
                    }
                }
            },
        ]
    });
   }
 }

这是我的错误:

ERROR in src/app/graphCytoscape/graph.component.ts(2,8): error TS2305: Module '"C:/Users/hudson.joubert/Documents/projects/cytoscopeJS/node_modules/@types/cytoscape/index"' has no

默认导出。

但我进入 node_modules 并且在那里,但我不知道如何解决这个问题。

【问题讨论】:

  • “没有”什么?您的错误信息不完整

标签: angular typescript types cytoscape.js


【解决方案1】:

对于这个错误:

src/app/graphCytoscape/graph.component.ts(2,8) 中的错误:错误 TS2305:模块 '"C:/Users/hudson.joubert/Documents/projects/cytoscopeJS/node_modules/@types/cytoscape/索引"' ...

你需要安装类型声明文件:npm import @types/cytoscape

【讨论】:

    猜你喜欢
    • 2021-03-25
    • 2017-03-29
    • 2021-12-20
    • 2022-01-16
    • 2020-11-13
    • 2017-03-18
    • 1970-01-01
    • 2018-09-04
    • 1970-01-01
    相关资源
    最近更新 更多