2017-01-22 56 views
11

我试图建立自己的角2/ASP.NET SPA在Visual Studio中。你可以找到所有的文件hereAngular2/ASP.NET - “没有的ResourceLoader实现已经提供了无法读取URL。”

我试图做的很简单:在我按照说明设置应用程序here后,我开始在自己的文件中添加以尝试执行一些基本路由,并删除了一些多余的文件。我有ClientApp/app/app.module.ts bootstrapping ClientApp/app/components/app/app.component.ts,唯一路由是ClientApp/app/components/app/test.component.ts

不幸的是,我得到这个错误:

An unhandled exception occurred while processing the request. 

Exception: Call to Node module failed with error: Error: No ResourceLoader implementation has been provided. Can't read the url "app.component.html" 
at Object.get (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:17454:17) 
at DirectiveNormalizer._fetch (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:13455:45) 
at DirectiveNormalizer.normalizeTemplateAsync (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:13498:23) 
at DirectiveNormalizer.normalizeDirective (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:13473:46) 
at RuntimeCompiler._createCompiledTemplate (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:16869:210) 
at C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:16807:43 
at Array.forEach (native) 
at C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:16805:50 
at Array.forEach (native) 
at RuntimeCompiler._compileComponents (C:\Users\Student\Source\Workspaces\mvs\Test2\Test2\node_modules\@angular\compiler\bundles\compiler.umd.js:16804:45) 

一切看起来正确的给我,但我是新来的两个角2和ASP.NET,所以我不知道这是否是一个编译器问题或人为错误。下面是一些代码,如果你需要了解更多信息的链接回购是在这个问题的顶部。

ClientApp /应用/ app.module.ts

import { NgModule } from '@angular/core'; 
import { RouterModule } from '@angular/router'; 
import { UniversalModule } from 'angular2-universal'; 
import { AppComponent } from './components/app/app.component'; 
import { TestComponent } from './components/app/test.component'; 

@NgModule({ 
    bootstrap: [ AppComponent ], 
    declarations: [ 
     AppComponent, 
     TestComponent 
    ], 
    imports: [ 
     UniversalModule, // Must be first import. This automatically imports BrowserModule, HttpModule, and JsonpModule too. 
     RouterModule.forRoot([ 
      { path: 'test', component: TestComponent }, 
      { path: '', redirectTo: 'test', pathMatch: 'full' }, 
      { path: '**', redirectTo: 'test' } 
     ]) 
    ] 
}) 
export class AppModule { 
} 

ClientApp /应用/组件/应用程序/ app.component.ts

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

@Component({ 
    selector: 'app', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 
} 

ClientApp /应用/组件/app/test.component.ts

import {Component, Input, OnInit} from '@angular/core'; 

@Component({ 
    templateUrl: './test.component.html', 
    styleUrls: ['./test.component.css'] 
}) 

export class TestComponent implements OnInit { 
    testing: String; 

    ngOnInit(): void { 
     this.testing = "This Works"; 
    } 
} 
+0

是否'app.component.html'存在吗?你在代码中引用它,但是你创建了它吗? –

+0

是的,它和app.component.ts在同一个文件夹中 –

+1

你有没有找到这个的原因?遇到同样的问题w/yeoman生成的项目。 – ohlando

回答

6

UniversalModule目前要求模板和样式的外部资产使用require()。

尝试更改templateUrl: './test.component.html'template: require('./test.component.html')。在这个问题上

而且styleUrls: ['./test.component.css']到​​

更多细节可以在这里找到:Unable to load assets without using require()

仅供参考,这里是从角问题线程在Github上:track runtime styleUrls。他们推荐使用angular2-template-loader。

0

检查您的WebPack版本(在命令行窗口中运行webpack --version),如果它是1.XX然后安装最新版本的WebPack 2(2.2.X),并就解决方案文件夹中运行它,然后再试一次

0

我碰上这一点,在我的情况的问题是从angular2-templeate装载机的升级。新版本“0.6.1”导致出现此错误。我介绍了以前的版本“0.6.0”,一切正常。

0

我有同样的问题,上述解决方案都没有帮助。但是,我看到的是Steve Sanderson YouTube videotemplateUrl一提:(和styleUrls:)可能只模板替换:(和风格:)。所以,我在黑暗中拍了一张照片。这固定的东西对我来说,我是能够移动到下一个关卡。

4

我的问题是我是小白的WebPack并试图执行一个tsc命令,按Steve Sanderson

causes VS to spew garbage .js files all over your source directories...

解决方法是

  1. 清理所有*.js*.js.map文件
  2. 确保<TypeScriptCompileBlocked>*.csproj
  3. 为true尝试r再次
0

unning项目对我来说,我从组件名称中除去连字符来解决这个问题: productlist.component =>错误 productlist.component => OK

1

angular2-template-loader出现这个问题SSR并有 几个原因会出现此问题:

  • 重要:检查是否angular2-template-loader是最新的。

通常,所有问题都与@Component有关。

  • 如将在组件名称中提到-。 (这已被固定)内@Component
  • 评论
相关问题