我正在嘗試使用新的角度2.0測試版自動化打字稿編譯。Angular2 beta和gulp-tsc - 找不到模塊'angular2/core'
的項目結構是:
myapp
|--node_modules
|---angular2
|--core.d.ts
|--...
|--lib
|--resources
|--app
|--app.component.ts
|--typings
|--..
.
|--package.json
|--gulpfile.js
app.component.ts摘錄:
import {Component, View} from 'angular2/core';
import {TechnologiesService} from './services';
當我運行打字稿命令(TSC)直接從殼一切順利並生成JavaScript文件。但是,當我運行我的gulp編譯任務時,有一些錯誤,因爲它沒有找到angular2/core和angular2/platform/browser模塊。爲什麼?
[16:35:55] Using gulpfile C:\dev\myapp\gulpfile.js
[16:35:55] Starting 'compile-ts'...
[16:35:55] Compiling TypeScript files using tsc version 1.8.2
[16:35:56] [tsc] > lib/resources/app/app.component.ts(1,46): error TS2307: Cannot find module 'angular2/core'.
[16:35:56] [tsc] > lib/resources/app/app.component.ts(44,14): error TS1219: Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.
[16:35:56] [tsc] > lib/resources/app/main.ts(1,28): error TS2307: Cannot find module 'angular2/platform/browser'.
[16:35:56] Failed to compile TypeScript: Error: tsc command has exited with code:2
events.js:154
throw er; // Unhandled 'error' event
^
Error: Failed to compile: tsc command has exited with code:2
gulpfile 打字稿編譯任務:
var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();
var typescript = require('gulp-tsc');
gulp.task('compile-ts', function(){
return gulp.src(['./lib/resources/app/**/*.ts'])
.pipe(typescript({"target": "es5", "module": "system", "moduleResolution": "node", "sourceMap": true,
"experimentalDecorators": true, "emitDecoraasdftorMetadata": true, "removeComments": false,
"noImplicitAny": false}))
.pipe(gulp.dest('./public/app/'));
});
您是否已安裝和包含類型碼?例如。 '/// ' –
martin
當我運行npm install時,typings文件夾被創建(myapp/typings)。試着添加'/// '但仍然抱怨angular2/core。還把'/// '並沒有任何變化。 –
codependent
我猜這是一個工作目錄問題。你有沒有試過指定rootDir? – Harangue