简体   繁体   English

在Visual Studio 2015 Update 1中找不到模块'angular2 / core'

[英]Cannot find module 'angular2/core' in Visual Studio 2015 Update 1

I came across this error Cannot find module 'angular2/core' when trying out the angular2 beta version in Visual Studio 2015 Update 1 . 我遇到了这个错误在Visual Studio 2015 Update 1中尝试使用angular2 beta版时无法找到模块'angular2 / core'

The code is below: 代码如下:

import {Component} from "angular2/core"

@Component({
    selector: 'my-app',
    template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent {
}

I have the angular2 beta version in my Visual Studio ASP.NET 5 project. 我在Visual Studio ASP.NET 5项目中有angular2 beta版本。 I have also enabled compile TS files when building the project. 我在构建项目时也启用了编译TS文件。

A few things that I tried, but none worked: 我试过的一些事情,但都没有奏效:

  1. I added /// <reference path="../node_modules/angular2/core.d.ts" /> at the top of the ts file. 我在ts文件的顶部添加了/// <reference path="../node_modules/angular2/core.d.ts" />

2. 2。

import {Component} from "angular2/bundles/angular2"

@Component({
    selector: 'my-app',
    template: '<h1>My First Angular 2 App</h1>'
})
export class AppComponent {
}

3. 3。

import {Component} from "../node_modules/angular2/core"

@Component({
    selector: 'my-app',
    template: "<h1>My First Angular 2 App</h1>"
})
export class AppComponent {
}

UPDATE: 更新:

This is my tsconfig.json 这是我的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"
  ]
}

UPDATE: 更新:

I added "moduleResolution": "node" to tsconfig.json file, but now I get another set of errors: 我在tsconfig.json文件中添加了 moduleResolution ”:“node” ,但现在又出现了另一组错误:

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> ------重建全部启动:项目: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: Duplicate identifier 'done'. 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: Duplicate identifier 'value'. 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): error TS2300: Build: Duplicate identifier 'EPSILON'. 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: Duplicate identifier 'MAX_SAFE_INTEGER'. 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: Duplicate identifier 'MIN_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: Duplicate identifier 'flags'. 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): error TS2300: Build: Duplicate identifier 'prototype'. 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): error TS2300: Build: Duplicate identifier 'size'. 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): error TS2300: Build: Duplicate identifier 'prototype'. 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): error TS2300: Build: Duplicate identifier 'size'. 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: Duplicate identifier 'prototype'. 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): error TS2300: Build: Duplicate identifier '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): error TS2300: Build: Duplicate identifier '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): error TS2300: Build: Duplicate identifier 'PropertyKey'. 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): error TS2300: Build: Duplicate identifier 'EPSILON'. 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): error TS2300: Build: Duplicate identifier 'MAX_SAFE_INTEGER'. 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): error TS2300: Build: Duplicate identifier 'MIN_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): error TS2300: Build: Duplicate identifier 'done'. 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: Duplicate identifier 'value'. 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: Duplicate identifier 'flags'. 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): error TS2300: Build: Duplicate identifier 'size'. 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): error TS2300: Build: Duplicate identifier 'prototype'. 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): error TS2300: Build: Duplicate identifier 'prototype'. 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): error TS2300: Build: Duplicate identifier 'size'. 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): error TS2300: Build: Duplicate identifier 'prototype'. 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): error TS2300: Build: Duplicate identifier '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): error TS2300: Build: Duplicate identifier 'prototype'. 1> C:\\ Program Files(x86)\\ Microsoft SDKs \\ TypeScript \\ 1.7 \\ lib.es6.d.ts(5099,5):错误TS2300:构建:重复标识符'原型'。 ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ========== ==========重建全部:0成功,1失败,0跳过==========

The typescript has come long way, and the Visual Studio 2015 Update 3 is available at this point in time with typescript version 2.0. 打字稿已经走了很长一段路, Visual Studio 2015 Update 3现在可用于打字稿版本2.0。

I found it the hard way that any syntax error in tsconfig.json can cause the same problem. 我发现tsconfig.json中的任何语法错误可能导致同样的问题。 I had a comma at the end of the last key of the compilerOptions , and that caused the ts files unable to find the modules correctly. 我在compilerOptions的最后一个键的末尾有一个逗号,这导致ts文件无法正确找到模块。

find the browser.d.ts file under your typings folder and drag into your app.ts or any ts file in your project. 找到typings文件夹下的browser.d.ts文件,然后将其拖入app.ts或项目中的任何ts文件。 you will get the ///reference xxxx, some error should be resolved 你会得到///参考xxxx,应该解决一些错误

I had the same issue. 我遇到过同样的问题。 I don't know what exactly did the trick. 我不知道究竟是什么伎俩。

  • Installed Angualr using npm: 使用npm安装Angualr:
    npm install Angular2 npm安装Angular2
  • Updated Visual Studio extension: 更新了Visual Studio扩展:
    DotNetCore.1.0.0.RC2-VS2015Tools.Preview1 DotNetCore.1.0.0.RC2-VS2015Tools.Preview1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在Visual Studio 2015中出现“找不到模块&#39;angular2 / core&#39;” Intellisense错误 - Why do I get “Cannot find module 'angular2/core'” Intellisense errors in Visual Studio 2015 Angular2组件相对路径Visual Studio 2015 module.id错误-找不到名称&#39;module&#39; - Angular2 Component Relative Paths Visual Studio 2015 module.id error - Cannot find name 'module' Angular2无法与Visual Studio 2015更新一起使用 - Angular2 not working with Visual Studio 2015 Update angular2:找不到模块&#39;@ angular / core&#39; - angular2: Cannot find module '@angular/core' 角度2:找不到模块“角度2 /核心” - Angular 2: Cannot find module 'angular2/core' 找不到模块&#39;@ angular / core&#39;visual studio 2017 - cannot find module '@angular/core' visual studio 2017 在 Visual Studio Code IDE 中找不到模块“@angular/core” - cannot find module '@angular/core' in Visual Studio Code IDE Angular2 找不到模块“angular2/core”,但应用程序有效 - Angular2 Cannot find module 'angular2/core' but application works visual studio 2015 / resharper支持angular2 - visual studio 2015 / resharper support for angular2 在Visual Studio 2015 for Angular2上启动项目 - Starting a project on Visual Studio 2015 for Angular2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM