2016-03-15 36 views
0

我目前有打字稿的問題。我正在嘗試使用關於使用express構建服務器的簡單教程(http://blog.edenmsg.com/angular2-typescript-gulp-and-expressjs/)。 所以我跟着inscructions,用tsd來安裝express。然後我嘗試啓動一飲而盡構建在該文件中所描述的:爲構建以下情況除外:(指數...乾淨,建):吞口和打字稿:node.d.ts不能編譯

gulpfile.js

/** 
* Created by alicia on 10/03/2016. 
*/ 
var gulp = require('gulp'); 
var path = require('path'); 
var sourcemaps = require('gulp-sourcemaps'); 
var ts = require('gulp-typescript'); 
var del = require('del'); 
var concat = require('gulp-concat') 
var runSequence = require('run-sequence'); 

// SERVER 
gulp.task('clean', function(){ 
    return del('dist') 
}); 

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

// CLIENT 

/* 
jsNPMDependencies 
*/ 
var jsNPMDependencies = [ 
    'angular2/bundles/angular2-polyfills.js', 
    'systemjs/dist/system.src.js', 
    'rxjs/bundles/Rx.js', 
    'angular2/bundles/angular2.dev.js', 
    'angular2/bundles/router.dev.js' 
] 

gulp.task('build:index', function(){ 
    var mappedPaths = jsNPMDependencies.map(file => {return path.resolve('node_modules', file)}) 

    //Let's copy our head dependencies into a dist/libs 
    var copyJsNPMDependencies = gulp.src(mappedPaths, {base:'node_modules'}) 
     .pipe(gulp.dest('dist/libs')); 

    var copyCss = gulp.src('client/css/**/*.css') 
     .pipe(gulp.dest('dist/css')); 

    //Let's copy our index into dist 
    var copyIndex = gulp.src('client/index.html') 
     .pipe(gulp.dest('dist')); 
    return [copyJsNPMDependencies, copyCss, copyIndex]; 
}); 

gulp.task('build:app', function(){ 
    var tsProject = ts.createProject('client/tsconfig.json'); 
    var tsResult = gulp.src('client/**/*.ts') 
     .pipe(sourcemaps.init()) 
     .pipe(ts(tsProject)) 
    return tsResult.js 
     .pipe(sourcemaps.write()) 
     .pipe(gulp.dest('dist/app')) 

}); 
var typescript = require('gulp-tsc'); 

gulp.task('compile', function(){ 
    gulp.src(['client/**/*.ts']) 
     .pipe(typescript()) 
     .pipe(gulp.dest('dist/')) 
}); 

gulp.task('build', function(callback){ 
    runSequence('clean', 'build:server', 
     'build:index', 
     'build:app', 
     callback); 
}); 

gulp.task('default', ['build']) 

每個任務編譯服務器。 這是我得到的錯誤:

[12:07:43] Starting 'build:server'... 
server/typings/node/node.d.ts(1759,52): error TS1005: '=' expected. 
server/typings/node/node.d.ts(1760,76): error TS1005: '=' expected. 
server/typings/node/node.d.ts(1761,52): error TS1005: '=' expected. 
server/typings/node/node.d.ts(1761,96): error TS1005: '=' expected. 
server/typings/node/node.d.ts(1771,54): error TS1005: '=' expected. 
server/typings/node/node.d.ts(1772,74): error TS1005: '=' expected. 
server/typings/node/node.d.ts(1773,54): error TS1005: '=' expected. 
server/typings/node/node.d.ts(1773,94): error TS1005: '=' expected. 

顯然,問題的根源node.d.ts.到來我真的不知道爲什麼它不工作,即使它是在絕對鍵入的版本。 你對如何提供幫助有什麼想法嗎?

編輯:我也有我的tscongig.json

{ 
    "compilerOptions": { 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "moduleResolution": "node", 
    "module": "commonjs", 
    "target": "es6", 
    "sourceMap": true, 
    "outDir": "dist", 
    "declaration": false, 
    "jsx": "react", 
    "noImplicitAny": false, 
    "removeComments": false 
    }, 
    "exclude": [ 
    "node_modules", 
    "typings/browser.d.ts", 
    "typings/browser" 
    ] 
} 

回答

0

試着改變你一口任務:

gulp.task('build:server', function() 
{ 
    var tsProject = ts.createProject('server/tsconfig.json'); 

    var tsResult = tsProject.src() 
     .pipe(sourcemaps.init()) 
     .pipe(ts(tsProject)); 

    return tsResult.js.pipe(concat('server.js')) 
     .pipe(sourcemaps.write()) 
     .pipe(gulp.dest('dist'))   
}); 

,並確保您使用「排除」部分喜歡在排除tsconfig node_modules這個例子:

{ 
    "compilerOptions": { 
     "emitDecoratorMetadata": true, 
     "experimentalDecorators": true, 
     "moduleResolution": "node", 
     "module": "commonjs", 
     "target": "es6", 
     "sourceMap": true, 
     "outDir": "dist", 
     "declaration": false, 
     "jsx": "react" 
    }, 
    "exclude": [ 
     "node_modules", 
     "typings/browser.d.ts", 
     "typings/browser" 
    ] 
} 
+0

我試過了,並更改了我的tsconfig.json文件(並將其包含在上面的文章中)。 我也改變了構建:服務器功能。但我仍然有完全相同的問題。我甚至試圖重新導入tsd和所有。但它仍然給出了同樣的錯誤。 – Licia

0

我有同樣的問題,我更新了我的package.json文件,以包括所有遲到st版本(對於大多數情況下,一些需要舊版本,因爲它們是其他版本的依賴關係,而新版本尚不支持)。這是我最後的package.json文件的樣子:

"dependencies": { 
    "angular2": "2.0.0-beta.17", 
    "es6-promise": "3.2.1", 
    "es6-shim": "0.35.1", 
    "express": "4.13.4", 
    "gulp-concat": "2.6.0", 
    "reflect-metadata": "0.1.2", 
    "rxjs": "5.0.0-beta.6", 
    "systemjs": "0.19.29", 
    "zone.js": "0.6.12", 
    "typescript": "1.8.10"}, 
"devDependencies": { 
    "del": "2.2.0", 
    "gulp": "3.9.1", 
    "gulp-concat": "2.6.0", 
    "gulp-sourcemaps": "1.6.0", 
    "gulp-typescript": "2.13.5", 
    "run-sequence": "1.2.1"} 

從我的研究,我可以推斷出它有事情做與不被支持了本例中使用的打字稿及咽版本。希望這可以幫助你排除Licia。