[英]Why do I get “Cannot find module 'angular2/core'” Intellisense errors in Visual Studio 2015
[英]Cannot find module 'angular2/core' in Visual Studio 2015 Update 1
我遇到了这个错误在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 {
}
我在Visual Studio ASP.NET 5项目中有angular2 beta版本。 我在构建项目时也启用了编译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"
]
}
更新:
我在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:构建:重复标识符'prototype'。 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跳过==========
打字稿已经走了很长一段路, Visual Studio 2015 Update 3现在可用于打字稿版本2.0。
我发现tsconfig.json中的任何语法错误都可能导致同样的问题。 我在compilerOptions的最后一个键的末尾有一个逗号,这导致ts文件无法正确找到模块。
找到typings文件夹下的browser.d.ts文件,然后将其拖入app.ts或项目中的任何ts文件。 你会得到///参考xxxx,应该解决一些错误
我遇到过同样的问题。 我不知道究竟是什么伎俩。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.