【发布时间】:2017-03-02 08:32:05
【问题描述】:
我正在尝试将 Angular JavaScript (ES5) 项目逐步迁移到 TypeScript 2.0,我必须承认我非常挣扎。
所以首先我将 index.js 更改为 index.ts 并使用 recommended method of installing typings (npm install --save @types/node) 而不是旧的 typings.json 方式。
构建设置使用gulp 和browserify,现在按照建议here 引入tsify 和babelify。
浏览
//...
.plugin(tsify)
.transform(babelify, {
presets: ['es2015'],
extensions: ['.ts', '.js']
})
//...
tsconfig.json
{
"files": [
"assets/app/index.ts"
],
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
}
}
但是构建失败:
TypeScript 错误:.tmp/public/app/index.ts(4,15):错误 TS2304:找不到名称“require”。
tsify 似乎没有将安装的类型复制到输出目录,导致上述错误。
关于如何解决问题的任何建议?
编辑
将 node_modules/@types 文件夹复制到我的 C: 驱动器的根目录可以消除错误,但我不知道为什么...
【问题讨论】:
标签: typescript gulp browserify tsify