使用类型在Angular 2中简单导入节点模块

时间:2016-10-11 16:44:41

标签: angularjs angular typescript-typings

我的文件的头部看起来像这样:

/// <reference path="../../typings/index.d.ts" />
import * as c3 from 'c3';

但是当我启动应用程序时,我收到了这个错误:

http://localhost:3000/c3 Failed to load resource: the server responded with a status of 404 (Not Found)

c3包含在package.json依赖项中。 typings.json看起来像:

{
  "globalDependencies": {
    "d3": "registry:dt/d3#0.0.0+20160907005744",
    "c3": "registry:dt/c3#0.0.0+20160926143332",
    "core-js": "registry:dt/core-js#0.0.0+20160725163759",
    "node": "registry:dt/node#6.0.0+20160831021119"
  }
}

而typings / index.d.ts看起来像是:

/// <reference path="globals/d3/index.d.ts" />
/// <reference path="globals/c3/index.d.ts" />
/// <reference path="globals/core-js/index.d.ts" />
/// <reference path="globals/node/index.d.ts" />

tsconfig.json看起来像:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true
  },
  "files": [
    "typings/index.d.ts"
  ]
}

有关错误配置的任何线索?

1 个答案:

答案 0 :(得分:1)

由于您正在使用SystemJS,因此您需要将模块添加到systemjs.config.js文件(或您称之为的任何文件)。您需要将模块添加到mappakcages对象。