我正在努力学习反应,但我无法启动npm。这是我的代码:
错误:
import numpy as np
import matplotlib.pyplot as plt
x = 10 ** np.random.random(10000) * 5
y = 10 ** np.random.random(10000) * 5
samps, xedges, yedges = np.histogram2d(np.log10(y), np.log10(x), bins=50)
plt.subplot(121)
p = plt.imshow(samps, extent=[0, 5, 0, 5])
plt.xlabel('Log10 X')
plt.ylabel('Log10 Y')
plt.subplot(122)
p = plt.imshow(samps, extent=[0, 5, 0, 5])
# The label handling stuff starts here
plt.pause(0.5) # Needed to make sure the drawing finished being created
plt.xlabel('X')
plt.ylabel('Y')
plt.draw()
ax = plt.gca()
lbx = ax.get_xticklabels()
lby = ax.get_yticklabels()
for i in range(len(lbx)):
lbx[i]._text = r'$10^' + lbx[i]._text + '$'
for i in range(len(lby)):
lby[i]._text = r'$10^' + lby[i]._text + '$'
ax.set_xticklabels(lbx)
ax.set_yticklabels(lby)
plt.show()
日志:
user:~/reactApp$ sudo npm start
> reactapp@1.0.0 start /home/user/reactApp
> webpack-dev-server --port 3000 --inline --content-base .
events.js:136
throw er; // Unhandled 'error' event
^
Error: listen EADDRNOTAVAIL 172.27.27.227:3000
at Object._errnoException (util.js:1031:13)
at _exceptionWithHostPort (util.js:1052:20)
at Server.setupListenHandle [as _listen2] (net.js:1350:19)
at listenInCluster (net.js:1408:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1523:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:102:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! reactapp@1.0.0 start: `webpack-dev-server --port 3000 --inline --content-base .`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the reactapp@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2018-02-19T10_56_13_668Z-debug.log
〜
的package.json
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@5.6.0
3 info using node@v9.2.0
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle reactapp@1.0.0~prestart: reactapp@1.0.0
6 info lifecycle reactapp@1.0.0~start: reactapp@1.0.0
7 verbose lifecycle reactapp@1.0.0~start: unsafe-perm in lifecycle true
8 verbose lifecycle reactapp@1.0.0~start: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/home/user/reactApp/node_modules/.bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin
9 verbose lifecycle reactapp@1.0.0~start: CWD: /home/user/reactApp
10 silly lifecycle reactapp@1.0.0~start: Args: [ '-c',
10 silly lifecycle 'webpack-dev-server --port 3000 --inline --content-base .' ]
11 silly lifecycle reactapp@1.0.0~start: Returned: code: 1 signal: null
12 info lifecycle reactapp@1.0.0~start: Failed to exec start script
13 verbose stack Error: reactapp@1.0.0 start: `webpack-dev-server --port 3000 --inline --content-base .`
13 verbose stack Exit status 1
13 verbose stack at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/index.js:285:16)
13 verbose stack at EventEmitter.emit (events.js:159:13)
13 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:55:14)
13 verbose stack at ChildProcess.emit (events.js:159:13)
13 verbose stack at maybeClose (internal/child_process.js:943:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:220:5)
14 verbose pkgid reactapp@1.0.0
15 verbose cwd /home/user/reactApp
16 verbose Linux 4.4.0-104-generic
17 verbose argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
18 verbose node v9.2.0
19 verbose npm v5.6.0
20 error code ELIFECYCLE
21 error errno 1
22 error reactapp@1.0.0 start: `webpack-dev-server --port 3000 --inline --content-base .`
22 error Exit status 1
23 error Failed at the reactapp@1.0.0 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]
webpack.config.js
{
"name": "reactapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --port 3000 --inline --content-base ."
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"react": "^16.2.0",
"react-dom": "^16.2.0",
"webpack": "^3.11.0"
},
"devDependencies": {
"webpack-dev-server": "^2.11.1"
}
}
尝试了,但找不到任何解决方案,任何人都可以帮我理解发生了什么,错误在哪里?如果您需要更多信息来调试此问题,请与我们联系。感谢
已通过更改端口检查编辑
答案 0 :(得分:2)
从错误中,您似乎正在尝试使用已经在使用的端口。您必须更改端口,或者必须终止正在使用该端口的进程。
您可以像这样更改端口:
"scripts": {
"start": "webpack-dev-server --port 4000 --inline --content-base ."
},
或者查找谁正在侦听端口3000,如lsof -i :3000
,然后终止进程{{1}}。我希望这会有所帮助。