Typescript模块未定义

时间:2016-05-10 10:04:07

标签: typescript

我正在升级到Angular2 RC1,我突然在一个非常简单的打字稿服务器上遇到以下错误: enter image description here

我已经安装了我需要的打字和我正在使用gulp构建它: typings.json:

{
  "ambientDependencies": {
  "es6-collections": "registry:dt/es6-collections#0.5.1+20160316155526",
  "es6-promise": "registry:dt/es6-promise#0.0.0+20160423074304",
  "es6-shim": "registry:dt/es6-shim#0.31.2+20160317120654",
  "express": "registry:dt/express#4.0.0+20160317120654",
  "express-serve-static-core": "registry:dt/express-serve-static-core#0.0.0+20160322035842",
  "node": "registry:dt/node#4.0.0+20160505172921",
  "require": "registry:dt/require#2.1.20+20160316155526",
  "serve-static": "registry:dt/serve-static#0.0.0+20160501131543"
  }
}
代理建设的gulp任务:

gulp.task('build:proxy', function () {
    var tsProject = ts.createProject('tsconfig.json');
    var tsResult = gulp.src(['proxy/**/*.ts','!proxy/typings/**/*.*'])
        .pipe(sourcemaps.init())
        .pipe(ts(tsProject))
    return tsResult.js
        .pipe(concat('proxy.js'))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('dist'))
});

和tsconfig.json:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false
  },
  "exclude": [
    "node_modules",
    "proxy/typings/main",
    "proxy/typings/main.d.ts"
  ],
  "buildOnSave": false,
  "disableCompileOnSave": true,
  "compileOnSave" : false
}    

因为在我保持导入相同之前,一切看起来都像是import express = require('express')。我似乎无法弄清楚我必须做些什么才能获得这些模块。

2 个答案:

答案 0 :(得分:1)

将新的main.d.ts放在代理文件夹中,内容低于内容

 /// <reference path="./typings/main.d.ts" />

答案 1 :(得分:1)

我回答了GitHub问题(https://github.com/typings/typings/issues/491)。总之,您需要更正gulp.src()调用以忽略所有类型,并且只忽略浏览器类型。例如。 gulp.src(['proxy/**/*.ts', '!proxy/typings/main/**', '!proxy/typings/main.d.ts']