一饮而尽,打字稿给模块找不到angular2错误 [英] gulp-typescript giving module not found error for angular2
问题描述
我用一饮而尽,打字稿编译angular2应用。我碰到下面的错误。
C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/async.d.ts(3,53):
错误TS2307:找不到模块'@ reactivex / rxjs /距离/ CJS /接收。
C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/async.d.ts(4,25):
错误TS2307:找不到模块'@ reactivex / rxjs /距离/ CJS /接收。
[12时十八分32秒]打字稿:4语义错误
C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/async.d.ts(5,22):
错误TS2307:找不到模块'@ reactivex / rxjs /距离/ CJS /操作员。
C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/lang.d.ts(2,22):
错误TS2304:找不到名称'BrowserNodeGlobal
块引用>这是一饮而尽任务。
paths.appJs =应用程序/ ** / * TS;
paths.appNg2ComponentsJs =ng2components / ** / * TS。
paths.appHtml =应用程序/ ** / * HTML;
paths.appJsOut = paths.webroot +应用程序/;
paths.angualr2Typings =node_modules / angular2 /分型/;gulp.task(编译应用程序组件功能(){ 变种tscResult = gulp.src([paths.appNg2ComponentsJs,paths.angualr2Typings +** / *。d.ts])
.pipe(TSC({
目标:ES5
模块:系统
宣言:假的,
noImplicitAny:假的,
removeComments:真实,
noLib:假的,
emitDecoratorMetadata:真实,
experimentalDecorators:真实,
sourceMap:真实,
listFiles:真实,
})); 返回tscResult.js
.pipe(gulp.dest(paths.appJsOut));
});
解决方案首先,你不应该添加
.d.ts
定义文件到您的一饮而尽生成任务:paths.appJs =应用程序/ ** / * TS;
paths.appNg2ComponentsJs =ng2components / ** / * TS。
paths.appHtml =应用程序/ ** / * HTML;
paths.appJsOut = paths.webroot +应用程序/;gulp.task(编译应用程序组件功能(){
VAR tscResult = gulp.src([paths.appNg2ComponentsJs,paths.appJs])
.pipe(TSC({
目标:ES5
模块:系统
宣言:假的,
noImplicitAny:假的,
removeComments:真实,
noLib:假的,
emitDecoratorMetadata:真实,
experimentalDecorators:真实,
sourceMap:真实,
listFiles:真
})); 返回tscResult.js
.pipe(gulp.dest(paths.appJsOut));
});此外,你需要写 P>
///<参考路径=路径/要/ file.d.ts/>
你的
.TS
脚本的开始线(即中那些paths.appJs
),他们在哪里必要时(打字稿编译器会告诉你,当它不知道的标识符)。I use gulp-typescript to compile the angular2 app. I get the following error.
C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/async.d.ts(3,53): error TS2307: Cannot find module '@reactivex/rxjs/dist/cjs/Rx'. C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/async.d.ts(4,25): error TS2307: Cannot find module '@reactivex/rxjs/dist/cjs/Rx'. [12:18:32] TypeScript: 4 semantic errors C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/async.d.ts(5,22): error TS2307: Cannot find module '@reactivex/rxjs/dist/cjs/Operator'. C:/src/Terminal.Web/src/Terminal.Web/node_modules/angular2/src/facade/lang.d.ts(2,22): error TS2304: Cannot find name 'BrowserNodeGlobal'.
This is the gulp task.
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)); });
解决方案First, you should not add
.d.ts
definition files to your gulp build task: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)); });
Moreover, you need to write
///<reference path="path/to/file.d.ts" />
lines at the beginning of your
.ts
scripts (i.e. to those inpaths.appJs
) where they are necessary (TypeScript compiler tells you when it does not know an identifier).这篇关于一饮而尽,打字稿给模块找不到angular2错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!