【问题标题】:Visual Studio 2017 throws compilation error in TypeScript file using angular 2Visual Studio 2017 使用 Angular 2 在 TypeScript 文件中引发编译错误
【发布时间】:2017-07-28 06:41:15
【问题描述】:

我正在尝试创建一个 Angular 2 应用程序

下面是打字稿代码

import { Component } from 'angular2/core';
@Component({
    selector: 'my-app',
    template: ' < h1 > My First SharePoint Add In using Angular2... !!! < /h1>'
})
export class AppComponent { }

它抛出以下错误

找不到模块 angular2/core

对装饰器的实验性支持是一项可能会在未来版本中更改的功能

第二个错误我也加了

"experimentalDecorators": true,

在 tsconfig.json 中

我还安装了TypeScript SDK for Visual Studio 2017 并重新启动了 Visual Studio,但没有运气

我也试过npm install -g typescript@latest

下面是我的 package.json

{
  "name": "imageslideshow",
  "version": "1.0.0",
  "description": "slide show for image libraries",
  "main": "index.js",
  "dependencies": {
    "@angular/core": "^4.3.2",
    "angular2": "^2.0.0-beta.17",
    "es6-promise": "^4.1.1",
    "es6-shim": "^0.35.3",
    "reflect-metadata": "^0.1.2",
    "rxjs": "^5.0.0-beta.6",
    "systemjs": "^0.20.17",
    "zone.js": "^0.8.16"
  },
  "devDependencies": {},
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "vignesh",
  "license": "ISC"
}

当我尝试 npm install 时,我收到以下消息

【问题讨论】:

  • 尝试运行'npm install'
  • 是的,我试过npm install -g typescript@latest
  • 不是 npm install -g 而是 npm install 在您的解决方案或您拥有软件包的子目录中
  • 您的package.json 文件是什么样的?
  • @Saravana 现在将其添加到问题中

标签: visual-studio angular typescript visual-studio-2017


【解决方案1】:
  1. 确保您已在项目上运行 npm install 并且 node_modules 文件夹中提供了依赖项。

  2. 在您的 package.json 文件中,您与 Angular 都有依赖关系 版本 2 和 4。决定要使用哪一个。

如果你想使用 Angular 4,你的导入应该是:

import { Component } from '@angular/core';

【讨论】:

  • 试过 npm install,但好像有问题
猜你喜欢
  • 2017-08-28
  • 2017-12-23
  • 2016-08-15
  • 2018-12-08
  • 1970-01-01
  • 1970-01-01
  • 2017-08-06
  • 1970-01-01
  • 2018-05-26
相关资源
最近更新 更多