2017-01-22 26 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
  • 評論
相關問題