【问题标题】:Failed to instantiate file "app.module.ts" from module "RootModule"无法从模块“RootModule”实例化文件“app.module.ts”
【发布时间】:2017-04-18 23:10:21
【问题描述】:

我有 sharepoint 插件项目,我已经包含了必要的 angular2 包和 ts 文件,如下面的解决方案资源管理器的 ss:

这是我的 ts 文件内容; boot.ts

import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent)

app.component.ts

import {Welcome} from './app.module';
import {Component} from 'angular2/core';
@Component({
    selector: 'app-main',
    template:'<h1>${Welcome.getMessage()}</h1>'
})
export class AppComponent {}

app.module.ts

export class Welcome {
    static getMessage() {
        return "Hello World!";
    }
}

当我运行此应用程序时,我总是在输出窗口中收到此错误消息:

> @"Error 1
>         CorrelationId: ae2bcaba-cdac-4178-bd39-2aca278a2e31
>         ErrorDetail: There was a problem with activating the app web definition.
>         ErrorType: App
>         ErrorTypeName: App Related
>         ExceptionMessage: Failed to instantiate file "app.module.ts" from module "RootModule": Source path
> "Features\SharePointAddIn4_Feature1\app.module.ts" not found.
>         Source: AppWeb
>         SourceName: App Web Deployment

我有搜索但找不到任何解决方案帮助我..知道如何解决这个问题吗?

【问题讨论】:

    标签: typescript1.8 sharepoint-addin


    【解决方案1】:

    要解决此问题,我必须将 tsconfig.json 文件(和其他文件)设置为不部署,并将其从项目根目录中的 Elements.xml 中删除。

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <Module Name="RootModule">
      </Module>
    </Elements>
    

    【讨论】:

      【解决方案2】:

      Hey Buddy,在回答之前有几点需要明确

      • 您使用的 angular2 版本太旧,可能是您使用的是 angular2 beta (当你使用'angular2/core' 现在它是'@angular/*'

      • 我说你使用了错误的语法

        {Welcome.getMessage()}

      有这样的语法

      {{Welcome.getMessage()}}
      
      • 您还试图访问类Welcome 甚至没有在app.component.ts 文件的构造函数中进行初始化,这是错误的。

      【讨论】:

      • 但我的 tsc -v 输出是 2.0.10 ?如果我将 'angular2/platform/browser' 更改为 '@angular/platform/browser' 它会显示错误“找不到模块..”
      • 是的,正如我已经说过的,您必须在 package.json 文件中将 Angular 版本升级到最终版本,而不是运行命令 npm install
      猜你喜欢
      • 2014-05-30
      • 2014-06-04
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多