2016-09-23 62 views
0

我正在使用Visual Studio 2015社區環境中的Angular2 (最新版本)項目。我已經設置了AoT的設置,並且正在輸出到/aot文件夾。Angular2 AoT 404加載編譯腳本時

當我運行該項目,我得到了我的瀏覽器中出現以下錯誤:

Failed to load resource: the server responded with a status of 404 (Not Found) 
http://localhost:15609/aot/app/app.module.ngfactory 

localhost/:28 Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:15609/aot/app/app.module.ngfactory 
    Error: XHR error (404 Not Found) loading http://localhost:15609/aot/app/app.module.ngfactory 
     at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:15609/node_modules/zone.js/dist/zone.js:647:29) 
     at ZoneDelegate.invokeTask (http://localhost:15609/node_modules/zone.js/dist/zone.js:236:37) 
     at Zone.runTask (http://localhost:15609/node_modules/zone.js/dist/zone.js:136:47) 
     at XMLHttpRequest.ZoneTask.invoke (http://localhost:15609/node_modules/zone.js/dist/zone.js:304:33) 
    Error loading http://localhost:15609/aot/app/app.module.ngfactory as "../aot/app/app.module.ngfactory" from http://localhost:15609/app/main.js 
     at XMLHttpRequest.wrapFn [as _onreadystatechange] (http://localhost:15609/node_modules/zone.js/dist/zone.js:647:29) 
     at ZoneDelegate.invokeTask (http://localhost:15609/node_modules/zone.js/dist/zone.js:236:37) 
     at Zone.runTask (http://localhost:15609/node_modules/zone.js/dist/zone.js:136:47) 
     at XMLHttpRequest.ZoneTask.invoke (http://localhost:15609/node_modules/zone.js/dist/zone.js:304:33) 
    Error loading http://localhost:15609/aot/app/app.module.ngfactory as "../aot/app/app.module.ngfactory" from http://localhost:15609/app/main.js(anonymous function) @ localhost/:28 

我可以找到該應用程序的文件夾結構內的文件。它在那裏,而不是空的。

我main.ts文件看起來像這樣:

import {platformBrowser} from '@angular/platform-browser'; 

import { AppModuleNgFactory } from '../aot/app/app.module.ngfactory'; 

platformBrowser().bootstrapModuleFactory(AppModuleNgFactory); 

如果需要,我可以提供其它所需的代碼。

回答

1

根據你的錯誤日誌錯誤您main.tsapp.module.ngfactory文件是app文件夾,使您的包括main.ts路徑應該import { AppModuleNgFactory } from 'app.module.ngfactory';

我覺得你的錯誤是因爲你的aot編譯後你的相對路徑不匹配。

+0

實際上,'../ aot/app/app.module.ngfactory'模塊確實被識別。但出於某種原因,不應該導入它應該。 我所做的只是編譯到一個根文件夾並像這樣訪問它:'。/ app/app.module.ngfactory'。我猜編譯器不喜歡什麼時候在文件夾樹上。 謝謝你的提示! – Nodios