在 Visual Studio 2015 Update 1 中找不到模块 'angular2/core'
Cannot find module 'angular2/core' in Visual Studio 2015 Update 1
我在 中试用 angular2 beta 版本时遇到此错误 找不到模块 'angular2/core' ]Visual Studio 2015年更新1.
代码如下:
import {Component} from "angular2/core"
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent {
}
我的 Visual Studio ASP.NET 5 项目中有 angular2 beta 版本。我在构建项目时也启用了编译TS文件。
一些我尝试过但 none 有效的方法:
- 我在 ts 文件的顶部添加了
/// <reference path="../node_modules/angular2/core.d.ts" />
。
2.
import {Component} from "angular2/bundles/angular2"
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent {
}
3.
import {Component} from "../node_modules/angular2/core"
@Component({
selector: 'my-app',
template: "<h1>My First Angular 2 App</h1>"
})
export class AppComponent {
}
更新:
这是我的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"
]
}
更新:
我添加了 "moduleResolution": "node" 到 tsconfig.json 文件,但现在我明白了另一组错误:
1>------ Rebuild All started: Project: Terminal.Web, Configuration:
Debug Any CPU ------
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(6,14):
error TS2300: Build: Duplicate identifier 'PropertyKey'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(9,5):
error TS2300: Build: Duplicate identifier 'done'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(10,5):
error TS2300: Build: Duplicate identifier 'value'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(248,5):
error TS2300: Build: Duplicate identifier 'EPSILON'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(283,5):
error TS2300: Build: Duplicate identifier 'MAX_SAFE_INTEGER'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(290,5):
error TS2300: Build: Duplicate identifier 'MIN_SAFE_INTEGER'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(346,5):
error TS2300: Build: Duplicate identifier 'flags'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(498,5):
error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(561,5):
error TS2300: Build: Duplicate identifier 'size'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(570,5):
error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(581,5):
error TS2300: Build: Duplicate identifier 'size'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(590,5):
error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(605,5):
error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(619,5):
error TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Program
Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(3841,14): error
TS2300: Build: Duplicate identifier 'PropertyKey'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4061,5): error
TS2300: Build: Duplicate identifier 'EPSILON'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4096,5): error
TS2300: Build: Duplicate identifier 'MAX_SAFE_INTEGER'. 1>C:\Program
Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4103,5): error
TS2300: Build: Duplicate identifier 'MIN_SAFE_INTEGER'. 1>C:\Program
Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4389,5): error
TS2300: Build: Duplicate identifier 'done'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4390,5): error
TS2300: Build: Duplicate identifier 'value'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4619,5): error
TS2300: Build: Duplicate identifier 'flags'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4647,5): error
TS2300: Build: Duplicate identifier 'size'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4657,5): error
TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4674,5): error
TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4686,5): error
TS2300: Build: Duplicate identifier 'size'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4696,5): error
TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4712,5): error
TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Program Files
(x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(5099,5): error
TS2300: Build: Duplicate identifier 'prototype'.
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
在您的 typings 文件夹下找到 browser.d.ts 文件并将其拖到您的 app.ts 或项目中的任何 ts 文件中。
你会得到 ///reference xxxx,应该解决一些错误
我遇到了同样的问题。我不知道到底是什么把戏。
- 使用 npm 安装 Angualr:
npm install Angular2
- 已更新 Visual Studio 扩展:
DotNetCore.1.0.0.RC2-VS2015Tools.Preview1
typescript 已经取得了长足的进步,Visual Studio 2015 更新 3 此时可用打字稿版本 2.0.
我发现 tsconfig.json 中的任何语法错误都可能导致同样的问题。我在 compilerOptions 的最后一个键的末尾有一个逗号,这导致 ts 文件无法正确找到模块。
我在 中试用 angular2 beta 版本时遇到此错误 找不到模块 'angular2/core' ]Visual Studio 2015年更新1.
代码如下:
import {Component} from "angular2/core"
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent {
}
我的 Visual Studio ASP.NET 5 项目中有 angular2 beta 版本。我在构建项目时也启用了编译TS文件。
一些我尝试过但 none 有效的方法:
- 我在 ts 文件的顶部添加了
/// <reference path="../node_modules/angular2/core.d.ts" />
。
2.
import {Component} from "angular2/bundles/angular2"
@Component({
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent {
}
3.
import {Component} from "../node_modules/angular2/core"
@Component({
selector: 'my-app',
template: "<h1>My First Angular 2 App</h1>"
})
export class AppComponent {
}
更新:
这是我的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"
]
}
更新:
我添加了 "moduleResolution": "node" 到 tsconfig.json 文件,但现在我明白了另一组错误:
1>------ Rebuild All started: Project: Terminal.Web, Configuration: Debug Any CPU ------ 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(6,14): error TS2300: Build: Duplicate identifier 'PropertyKey'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(9,5): error TS2300: Build: Duplicate identifier 'done'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(10,5): error TS2300: Build: Duplicate identifier 'value'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(248,5): error TS2300: Build: Duplicate identifier 'EPSILON'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(283,5): error TS2300: Build: Duplicate identifier 'MAX_SAFE_INTEGER'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(290,5): error TS2300: Build: Duplicate identifier 'MIN_SAFE_INTEGER'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(346,5): error TS2300: Build: Duplicate identifier 'flags'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(498,5): error TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(561,5): error TS2300: Build: Duplicate identifier 'size'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(570,5): error TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(581,5): error TS2300: Build: Duplicate identifier 'size'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(590,5): error TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(605,5): error TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(619,5): error TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(3841,14): error TS2300: Build: Duplicate identifier 'PropertyKey'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4061,5): error TS2300: Build: Duplicate identifier 'EPSILON'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4096,5): error TS2300: Build: Duplicate identifier 'MAX_SAFE_INTEGER'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4103,5): error TS2300: Build: Duplicate identifier 'MIN_SAFE_INTEGER'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4389,5): error TS2300: Build: Duplicate identifier 'done'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4390,5): error TS2300: Build: Duplicate identifier 'value'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4619,5): error TS2300: Build: Duplicate identifier 'flags'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4647,5): error TS2300: Build: Duplicate identifier 'size'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4657,5): error TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4674,5): error TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4686,5): error TS2300: Build: Duplicate identifier 'size'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4696,5): error TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(4712,5): error TS2300: Build: Duplicate identifier 'prototype'. 1>C:\Program Files (x86)\Microsoft SDKs\TypeScript.7\lib.es6.d.ts(5099,5): error TS2300: Build: Duplicate identifier 'prototype'. ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
在您的 typings 文件夹下找到 browser.d.ts 文件并将其拖到您的 app.ts 或项目中的任何 ts 文件中。 你会得到 ///reference xxxx,应该解决一些错误
我遇到了同样的问题。我不知道到底是什么把戏。
- 使用 npm 安装 Angualr:
npm install Angular2 - 已更新 Visual Studio 扩展:
DotNetCore.1.0.0.RC2-VS2015Tools.Preview1
typescript 已经取得了长足的进步,Visual Studio 2015 更新 3 此时可用打字稿版本 2.0.
我发现 tsconfig.json 中的任何语法错误都可能导致同样的问题。我在 compilerOptions 的最后一个键的末尾有一个逗号,这导致 ts 文件无法正确找到模块。