2017-04-24 75 views
1

我正在嘗試使用Karma進行測試,我正在關注Angulars自己的測試指南。目前,我正在使用最基本的測試課程,但在運行時遇到問題。Npm測試無法找到socket.io.js文件

測試類:

describe('1st test',()=>{ 
it('true is true',()=> expect(true).toBe(true)); }); 

當我運行使用NPM測試我得到的命令提示符下鍵入以下錯誤:

[1] 24 04 2017 11:27:24.957:WARN [web-server]: 404: /base/node_modules/socket.io-client/dist/socket.io.js 
[1] Chrome 57.0.2987 (Windows 10 0.0.0) ERROR 
[1] { 
[1]  "__zone_symbol__error": { 
[1]  "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js" 
[1]  }, 
[1]  "stack": "(SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "name": "Error", 
[1]  "message": "(SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "__zone_symbol__stack": "(SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "originalErr": { 
[1]  "__zone_symbol__error": { 
[1]   "originalStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]   "zoneAwareStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js" 
[1]  }, 
[1]  "stack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "name": "Error", 
[1]  "message": "XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "originalStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "zoneAwareStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "__zone_symbol__currentTask": { 
[1]   "type": "microTask", 
[1]   "state": "notScheduled", 
[1]   "source": "Promise.then", 
[1]   "zone": "<root>", 
[1]   "cancelFn": null, 
[1]   "runCount": 0 
[1]  }, 
[1]  "__zone_symbol__stack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "__zone_symbol__message": "XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "__zone_symbol__name": "Error", 
[1]  "__zone_symbol__originalStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "__zone_symbol__zoneAwareStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js" 
[1]  }, 
[1]  "__zone_symbol__currentTask": { 
[1]  "type": "microTask", 
[1]  "state": "notScheduled", 
[1]  "source": "Promise.then", 
[1]  "zone": "<root>", 
[1]  "cancelFn": null, 
[1]  "runCount": 0 
[1]  }, 
[1]  "__zone_symbol__name": "Error", 
[1]  "__zone_symbol__message": "(SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "__zone_symbol__originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "__zone_symbol__zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js" 
[1] } 
[1] 
[1] Chrome 57.0.2987 (Windows 10 0.0.0) ERROR 
[1] { 
[1]  "__zone_symbol__error": { 
[1]  "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js" 
[1]  }, 
[1]  "stack": "(SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "name": "Error", 
[1]  "message": "(SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "__zone_symbol__stack": "(SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "originalErr": { 
[1]  "__zone_symbol__error": { 
[1]   "originalStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]   "zoneAwareStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js" 
[1]  }, 
[1]  "stack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "name": "Error", 
[1]  "message": "XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "originalStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "zoneAwareStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "__zone_symbol__currentTask": { 
[1]   "type": "microTask", 
[1]   "state": "notScheduled", 
[1]   "source": "Promise.then", 
[1]   "zone": "<root>", 
[1]   "cancelFn": null, 
[1]   "runCount": 0 
[1]  }, 
[1]  "__zone_symbol__stack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "__zone_symbol__message": "XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "__zone_symbol__name": "Error", 
[1]  "__zone_symbol__originalStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js", 
[1]  "__zone_symbol__zoneAwareStack": "Error: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js" 
[1]  }, 
[1]  "__zone_symbol__currentTask": { 
[1]  "type": "microTask", 
[1]  "state": "notScheduled", 
[1]  "source": "Promise.then", 
[1]  "zone": "<root>", 
[1]  "cancelFn": null, 
[1]  "runCount": 0 
[1]  }, 
[1]  "__zone_symbol__name": "Error", 
[1]  "__zone_symbol__message": "(SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "__zone_symbol__originalStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js", 
[1]  "__zone_symbol__zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError: XHR error (404 Not Found) loading src/node_modules/socket.io-client/dist/socket.io.js\n\tError loading src/node_modules/socket.io-client/dist/socket.io.js as \"socket.io-client\" from src/app/global/socket.service.js" 
[1] } 

我已經檢查了它無法找到該文件並將其存在於錯誤所述的目錄中,所以我不知道該怎麼做。

回答

0

這些是XHR請求的404錯誤。這並不意味着該文件不存在於文件系統中,但它不是通過訪問該特定路徑來提供的。您的服務器不太可能服務於整個文件系統,因此您不應該擔心該文件是否存在,但是如果它是從您的程序試圖訪問的特定URL中提供的。

看到代碼的例子在這個答案的例子:

這裏socket.io.js文件以HTML引用爲:

<script src="/socket.io/socket.io.js"></script> 

不是絕對路徑在文件系統中,而不是包含node_modules的路徑。 HTTP請求中的路徑和文件系統中的路徑是不同的,404錯誤是HTTP特定的。

+0

但我如何解決這個錯誤對我來說?我真的不知道要改變什麼以及在哪裏。 – MoeTheBro