【发布时间】:2016-09-05 05:45:15
【问题描述】:
我正在升级到 Angular2 RC1,但在一个非常简单的打字稿服务器上突然出现以下错误:
我已经安装了我认为需要的类型,并且正在使用 gulp 构建它: 打字.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')。我似乎无法弄清楚我必须做什么才能让这些模块进入。
【问题讨论】:
-
你检查过
typings/main.d.ts吗? -
您的源 ts 文件是否驻留在代理\\ts 文件中?
-
@Zen 不错,看起来不错!
-
@MadhuRanjan 代理文件夹内只有一个名为 proxy.ts 的 ts 文件。我也尝试将所有内容移至根文件夹,但同样的问题。
标签: typescript