won*_*rld 13 typescript angular
我遇到了这个错误在Visual Studio 2015 Update 1中尝试使用angular2 beta版时无法找到模块'angular2/core'.
代码如下:
import {Component} from "angular2/core"
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent {
}
Run Code Online (Sandbox Code Playgroud)
我在Visual Studio ASP.NET 5项目中有angular2 beta版本.我在构建项目时也启用了编译TS文件.
我试过的一些事情,但都没有奏效:
/// <reference path="../node_modules/angular2/core.d.ts" />在ts文件的顶部添加了.2.
import {Component} from "angular2/bundles/angular2"
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent {
}
Run Code Online (Sandbox Code Playgroud)
3.
import {Component} from "../node_modules/angular2/core"
@Component({
selector: 'my-app',
template: "<h1>My First Angular 2 App</h1>"
})
export class AppComponent {
}
Run Code Online (Sandbox Code Playgroud)
更新:
这是我的tsconfig.json
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": true,
"sourceMap": true,
"target": "es6",
"module": "system",
"emitDecoratorMetadata": true,
"experimentalDecorators": true
},
"exclude": [
"node_modules",
"wwwroot",
"bower_components"
]
}
Run Code Online (Sandbox Code Playgroud)
更新:
我在tsconfig.json文件中添加了" moduleResolution ":"node",但现在又出现了另一组错误:
1> ------重建全部启动:项目:Terminal.Web,配置:调试任何CPU ------ 1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim. d.ts(6,14):错误TS2300:构建:重复标识符'PropertyKey'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(9,5):error TS2300:Build:重复的标识符'done'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(10,5):error TS2300:Build:重复标识符'value'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(248,5):错误TS2300:构建:重复标识符'EPSILON'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(283,5):error TS2300:Build:重复标识符'MAX_SAFE_INTEGER'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(290,5):error TS2300:Build:重复标识符'MIN_SAFE_INTEGER'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(346,5):error TS2300:Build:重复标识符'flags'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(498,5):错误TS2300:构建:重复标识符'原型'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(561,5):错误TS2300:构建:重复标识符'大小'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(570,5):错误TS2300:构建:重复标识符'原型'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(581,5):错误TS2300:构建:重复标识符'大小'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(590,5):error TS2300:Build:重复标识符'prototype'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(605,5):错误TS2300:构建:重复标识符'prototype'.1> C:\ Test \node_modules\angular2\typings\es6-shim\es6-shim.d.ts(619,5):错误TS2300:构建:重复标识符'原型'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(3841,14):错误TS2300:构建:重复标识符'PropertyKey'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4061,5):错误TS2300:构建:重复标识符'EPSILON'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4096,5):错误TS2300:构建:重复标识符'MAX_SAFE_INTEGER'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4103,5):错误TS2300:构建:重复标识符'MIN_SAFE_INTEGER'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4389,5):错误TS2300:构建:重复标识符"已完成".1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4390,5):error TS2300:Build:重复标识符'value'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4619,5):error TS2300:Build:重复标识符'flags'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4647,5):错误TS2300:构建:重复标识符'大小'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4657,5):错误TS2300:构建:重复标识符'原型'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4674,5):错误TS2300:构建:重复标识符'原型'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4686,5):错误TS2300:构建:重复标识符'大小'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4696,5):错误TS2300:构建:重复标识符'原型'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4712,5):错误TS2300:构建:重复标识符'原型'.1> C:\ Program Files(x86)\ Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(5099,5):错误TS2300:构建:重复标识符'原型'.==========重建全部:0成功,1失败,0跳过==========
Typescript已经取得了长足的进步,Visual Studio 2015 Update 3目前已与 Typescript 2.0 版本一起发布。
我发现tsconfig.json中的任何语法错误都可能导致同样的问题。我在compilerOptions最后一个键的末尾有一个逗号,这导致 ts 文件无法正确找到模块。
| 归档时间: |
|
| 查看次数: |
16021 次 |
| 最近记录: |