我正在尝试通过在我的控制台中键入npm run test来运行我的测试(mocha)。它在昨天工作,直到我删除了我的团队编写的一些代码。出于某种原因搞砸了。我们正在编写一个使用Socket.io的应用程序,由于某种原因它出现在cmd中。我也是在PC上运行它。这是我在进行npm run test时给出的错误:
$ npm run test
> potentpotables@1.0.0 test C:\Users\name\Desktop\my_app
> mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test
>C:\Users\name\Desktop\my_app\node_modules\socket.io-client\lib\url.js:29
if (null == uri) uri = loc.protocol + '//' + loc.host;
^
TypeError: Cannot read property 'protocol' of undefined
at url (C:\Users\name\Desktop\my_app\node_modules\socket.io-client\lib\url.js:29:29)
at lookup (C:\Users\name\Desktop\my_app\node_modules\socket.io-client\lib\index.js:44:16)
at Object.<anonymous> (sockets_client.js:2:13)
at Module._compile (module.js:409:26)
at loader (C:\Users\name\Desktop\my_app\node_modules\babel-core\node_modules\babel-register\lib\node.js:158:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\Users\name\Desktop\my_app\node_modules\babel-core\node_modules\babel-register\lib\node.js:168:7)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (index.js:3:1)
at Module._compile (module.js:409:26)
at loader (C:\Users\name\Desktop\my_app\node_modules\babel-core\node_modules\babel-register\lib\node.js:158:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\Users\name\Desktop\my_app\node_modules\babel-core\node_modules\babel-register\lib\node.js:168:7)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (sessionID_reducer.js:1:1)
at Module._compile (module.js:409:26)
at loader (C:\Users\name\Desktop\my_app\node_modules\babel-core\node_modules\babel-register\lib\node.js:158:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\Users\name\Desktop\my_app\node_modules\babel-core\node_modules\babel-register\lib\node.js:168:7)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (index.js:2:1)
at Module._compile (module.js:409:26)
at loader (C:\Users\name\Desktop\my_app\node_modules\babel-core\node_modules\babel-register\lib\node.js:158:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\Users\name\Desktop\my_app\node_modules\babel-core\node_modules\babel-register\lib\node.js:168:7)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (test_helper.js:9:1)
at Module._compile (module.js:409:26)
at loader (C:\Users\name\Desktop\my_app\node_modules\babel-core\node_modules\babel-register\lib\node.js:158:5)
at Object.require.extensions.(anonymous function) [as .js] (C:\Users\name\Desktop\my_app\node_modules\babel-core\node_modules\babel-register\lib\node.js:168:7)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at C:\Users\name\Desktop\my_app\node_modules\mocha\bin\_mocha:311:3
at Array.forEach (native)
at Object.<anonymous> (C:\Users\name\Desktop\my_app\node_modules\mocha\bin\_mocha:310:10)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
npm ERR! node v4.4.3
npm ERR! npm v2.15.1
npm ERR! code ELIFECYCLE
npm ERR! my_app@1.0.0 test: `mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the my_app@1.0.0 test script 'mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test'.
npm ERR! This is most likely a problem with the my_app package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs my_app
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls my_app
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! C:\Users\name\Desktop\my_app\npm-debug.log`
这是我的package.json:
"scripts": {
"start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
"test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
"test:watch": "npm run test -- --watch",
"dev": "nodemon server/server.js"
}
说实话,我不完全确定这里发生了什么。我刚刚从一个样板运行良好的锅炉板的package.json中复制了一些代码。我知道它使用的是我编写的test_helper.js代码,但我不确定它还在做什么。最后这里是npm调试日志:
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'test' ]
2 info using npm@2.15.1
3 info using node@v4.4.3
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info pretest my_app@1.0.0
6 info test my_app@1.0.0
7 verbose unsafe-perm in lifecycle true
8 info my_app@1.0.0 Failed to exec test script
9 verbose stack Error: my_app@1.0.0 test: `mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test`
9 verbose stack Exit status 1
9 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:217:16)
9 verbose stack at emitTwo (events.js:87:13)
9 verbose stack at EventEmitter.emit (events.js:172:7)
9 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14)
9 verbose stack at emitTwo (events.js:87:13)
9 verbose stack at ChildProcess.emit (events.js:172:7)
9 verbose stack at maybeClose (internal/child_process.js:827:16)
9 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
10 verbose pkgid my_app@1.0.0
11 verbose cwd C:\Users\name\Desktop\my_app
12 error Windows_NT 10.0.10586
13 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
14 error node v4.4.3
15 error npm v2.15.1
16 error code ELIFECYCLE
17 error my_app@1.0.0 test: `mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test`
17 error Exit status 1
18 error Failed at the my_app@1.0.0 test script 'mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test'.
18 error This is most likely a problem with the my_app package,
18 error not with npm itself.
18 error Tell the author that this fails on your system:
18 error mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test
18 error You can get information on how to open an issue for this project with:
18 error npm bugs my_app
18 error Or if that isn't available, you can get their info via:
18 error
18 error npm owner ls my_app
18 error There is likely additional logging output above.
19 verbose exit [ 1, true ]
谢谢你看看!
答案 0 :(得分:0)
无论传递给socket.io的URL是undefined
。
你能分享使用socket.io的任何代码吗?它可能看起来像:
var socket = require('socket.io-client')('http://localhost');
如果&#39; http://localhost&#39;您将收到该错误在该代码中undefined