typescript 在 Visual Studio 2015 Update 1 中找不到模块“angular2/core”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34312869/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 03:09:57  来源:igfitidea点击:

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

typescriptangular

提问by wonderful world

I came across this error Cannot find module 'angular2/core'when trying out the angular2 betaversion 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 betaversion in my Visual Studio ASP.NET 5project. I have also enabled compile TS files when building the project.

我的Visual Studio ASP.NET 5项目中有angular2 测试版。我在构建项目时也启用了编译 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 tsfile.
  1. /// <reference path="../node_modules/angular2/core.d.ts" />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.jsonfile, 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>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\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(4061,5): error TS2300: Build: Duplicate identifier '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(4103,5): error TS2300: Build: Duplicate identifier '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(4390,5): error TS2300: Build: Duplicate identifier '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(4647,5): error TS2300: Build: Duplicate identifier 'size'. 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(4674,5): error TS2300: Build: Duplicate identifier 'prototype'. 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(4696,5): error TS2300: Build: Duplicate identifier '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(5099,5): error TS2300: Build: Duplicate identifier 'prototype'. ========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

1>------ 重建全部开始:项目:Terminal.Web,配置:Debug Any CPU------ 1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim。 d.ts(6,14): 错误 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): 错误 TS2300: Build: Duplicate identifier 'EPSILON'。1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(283,5): 错误 TS2300: Build: Duplicate identifier 'MAX_SAFE_INTEGER'。1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d。ts(290,5):错误 TS2300:构建:重复标识符“MIN_SAFE_INTEGER”。1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(346,5): 错误 TS2300: Build: Duplicate identifier 'flags'。1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(498,5): 错误 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): 错误 TS2300:构建:重复标识符“原型”。1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(605,5): 错误 TS2300: Build: Duplicate identifier 'prototype'。1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(619,5): 错误 TS2300: Build: Duplicate identifier 'prototype'。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(4061,5): error TS2300: Build: Duplicate identifier '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(4103,5): 错误 TS2300: Build: Duplicate identifier '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(4390,5): error TS2300: Build: Duplicate identifier '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(4647,5): error TS2300: Build: Duplicate identifier 'size'。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(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(4696,5): error TS2300: Build: Duplicate identifier '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(5099,5): error TS2300: Build: Duplicate identifier 'prototype'。========== 全部重建:0 成功,1 失败,0 跳过 ========== 重复的标识符“原型”。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(4696,5): error TS2300: Build: Duplicate identifier '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(5099,5): error TS2300: Build: Duplicate identifier 'prototype'。========== 全部重建:0 成功,1 失败,0 跳过 ========== 重复的标识符“原型”。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(4696,5): error TS2300: Build: Duplicate identifier '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(5099,5): error TS2300: Build: Duplicate identifier 'prototype'。========== 全部重建:0 成功,1 失败,0 跳过 ========== 尺寸'。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(4712,5): error TS2300: Build: Duplicate identifier 'prototype'。1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(5099,5): error TS2300: Build: Duplicate identifier 'prototype'。========== 全部重建:0 成功,1 失败,0 跳过 ========== 尺寸'。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(4712,5): error TS2300: Build: Duplicate identifier 'prototype'。1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(5099,5): error TS2300: Build: Duplicate identifier 'prototype'。========== 全部重建:0 成功,1 失败,0 跳过 ========== \Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(5099,5):错误 TS2300:构建:重复标识符“原型”。========== 全部重建:0 成功,1 失败,0 跳过 ========== \Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(5099,5):错误 TS2300:构建:重复标识符“原型”。========== 全部重建:0 成功,1 失败,0 跳过 ==========

采纳答案by wonderful world

The typescripthas come long way, and the Visual Studio 2015 Update 3is available at this point in time with typescript version 2.0.

打字稿已经取得了长足的进步Visual Studio 2015 更新 3在这个时间点可以使用打字稿 2.0 版。

I found it the hard way that any syntax error in tsconfig.jsoncan cause the same problem. 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.

我发现tsconfig.json中的任何语法错误可能导致同样的问题。我在compilerOptions的最后一个键的末尾有一个逗号,这导致 ts 文件无法正确找到模块。

回答by VincentGuo

find the browser.d.ts file under your typings folder and drag into your app.ts or any ts file in your project. you will get the ///reference xxxx, some error should be resolved

在typings 文件夹下找到browser.d.ts 文件,然后拖入您的app.ts 或项目中的任何ts 文件。您将获得 ///reference xxxx,应该解决一些错误

回答by BabyGuru

I had the same issue. I don't know what exactly did the trick.

我遇到过同样的问题。我不知道究竟是什么把戏。

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