[英]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.