Npm测试找不到socket.io.js文件

时间:2017-04-24 09:55:18

标签: node.js angular testing npm

我正在尝试使用Karma进行测试,我正在遵循Angulars自己的测试指南。目前我正在使用最基本的测试类,但运行它时遇到问题。

测试类:

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

当我使用npm test运行它时,我在命令提示符中收到以下错误:

 [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]   } 

我检查了它找不到的文件,它存在于错误所述的目录中,所以我不知道该怎么做。

1 个答案:

答案 0 :(得分:0)

这些是XHR请求的404错误。它并不意味着该文件不存在于文件系统中,而是通过访问该特定路径来提供服务。您的服务器不太可能为整个文件系统提供服务,因此如果文件存在与否,您不应该担心,但是如果它是从您的程序试图访问它的特定URL提供的话。

请参阅本答案中的代码示例以获取示例:

此处socket.io.js文件在HTML中被引用为:

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

不是文件系统中的绝对路径,也不是包含node_modules的路径。文件系统中HTTP请求和路径中的路径是不同的,404错误是HTTP特定的。