gulp-typescript给出模块未找到angular2的错误

时间:2015-11-14 19:13:29

标签: gulp angular

我使用gulp-typescript编译angular2 app。我收到以下错误。

  

C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/async.d.ts(3,53):   错误TS2307:找不到模块' @activex / rxjs / dist / cjs / Rx'。   C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/async.d.ts(4,25):   错误TS2307:找不到模块' @activex / rxjs / dist / cjs / Rx'。   [12:18:32] TypeScript:4个语义错误   C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/async.d.ts(5,22):   错误TS2307:找不到模块' @activex / rxjs / dist / cjs / Operator'。   C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/lang.d.ts(2,22):   错误TS2304:找不到名称' BrowserNodeGlobal'。

这是gulp任务。

paths.appJs = "app/**/*.ts";
paths.appNg2ComponentsJs = "ng2components/**/*.ts";
paths.appHtml = "app/**/*.html";
paths.appJsOut = paths.webroot + "app/";
paths.angualr2Typings = "node_modules/angular2/typings/";

gulp.task("compile-app-components", function () {

    var tscResult = gulp.src([paths.appNg2ComponentsJs, paths.angualr2Typings + "**/*.d.ts"])
        .pipe(tsc({
            "target": "es5",
            "module": "system",
            "declaration": false,
            "noImplicitAny": false,
            "removeComments": true,
            "noLib": false,
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "sourceMap": true,
            "listFiles": true,
        }));

    return tscResult.js
        .pipe(gulp.dest(paths.appJsOut));
});

2 个答案:

答案 0 :(得分:1)

首先,您不应将.d.ts定义文件添加到gulp构建任务中:

paths.appJs = "app/**/*.ts";
paths.appNg2ComponentsJs = "ng2components/**/*.ts";
paths.appHtml = "app/**/*.html";
paths.appJsOut = paths.webroot + "app/";

gulp.task("compile-app-components", function () {    
    var tscResult = gulp.src([paths.appNg2ComponentsJs, paths.appJs])
        .pipe(tsc({
            "target": "es5",
            "module": "system",
            "declaration": false,
            "noImplicitAny": false,
            "removeComments": true,
            "noLib": false,
            "emitDecoratorMetadata": true,
            "experimentalDecorators": true,
            "sourceMap": true,
            "listFiles": true
        }));

    return tscResult.js
        .pipe(gulp.dest(paths.appJsOut));
});

此外,你需要写

///<reference path="path/to/file.d.ts" />

.ts脚本开头的行(即paths.appJs中的行)(TypeScript编译器会告诉您何时不知道标识符)。

答案 1 :(得分:1)

如果您使用JSPM,解决方案是将tsconfig移至wwwroot

将以下行添加到wwwroot / tsconfig.json中,以便systemjs不会尝试加载源图:

{
  "compilerOptions": {
    "target": "es5",
    "module": "commonjs",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "sourceMap": false
  },
  "exclude": [
    "jspm_packages"
  ]
}