最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Windows 10中ReactJS项目npm run dev出错:Error: spawn webpack-dev-server ENOENT

Windows crifan 15862浏览 0评论

Windows中,下载一个已有代码的在Mac中可以正常运行的ReactJS的Preact项目后,去运行

npm run dev

但出错:

Error: spawn webpack-dev-server ENOENT
    at notFoundError (C:\Users\ABC\WebstormProjects\ucowsapp\node_modules\cross-spawn\lib\enoent.js:11:11)
    at verifyENOENT (C:\Users\ABC\WebstormProjects\ucowsapp\node_modules\cross-spawn\lib\enoent.js:46:16)
    at ChildProcess.cp.emit (C:\Users\ABC\WebstormProjects\ucowsapp\node_modules\cross-spawn\lib\enoent.js:33:19)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:197:12)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] dev: `cross-env NODE_ENV=development webpack-dev-server –inline –hot –progress`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] dev 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!     C:\Users\ABC\AppData\Roaming\npm-cache\_logs\2017-08-01T03_33_15_935Z-debug.log

第二次继续出错,对应log文件内容为:

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   ‘dev’,
1 verbose cli   ‘–scripts-prepend-node-path=auto’ ]
2 info using [email protected]
3 info using [email protected]
4 verbose run-script [ ‘predev’, ‘dev’, ‘postdev’ ]
5 info lifecycle [email protected]~predev: [email protected]
6 silly lifecycle [email protected]~predev: no script for predev, continuing
8 verbose lifecycle [email protected]~dev: unsafe-perm in lifecycle true
9 verbose lifecycle [email protected]~dev: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Users\ABC\WebstormProjects\ucowsapp\node_modules\.bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\ProgramData\chocolatey\bin;C:\Program Files\nodejs\;C:\Program Files\Java\jdk1.8.0_91\bin;C:\Users\ABC\AppData\Roaming\npm;D:\android-sdk-windows\platform-tools;C:\Program Files (x86)\Microsoft VS Code\bin
10 verbose lifecycle [email protected]~dev: CWD: C:\Users\ABC\WebstormProjects\ucowsapp
11 silly lifecycle [email protected]~dev: Args: [ ‘/d /s /c’,
11 silly lifecycle   ‘cross-env NODE_ENV=development webpack-dev-server –inline –hot –progress’ ]
12 silly lifecycle [email protected]~dev: Returned: code: 1  signal: null
13 info lifecycle [email protected]~dev: Failed to exec dev script
14 verbose stack Error: [email protected] dev: `cross-env NODE_ENV=development webpack-dev-server –inline –hot –progress`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:283:16)
14 verbose stack     at emitTwo (events.js:125:13)
14 verbose stack     at EventEmitter.emit (events.js:213:7)
14 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:125:13)
14 verbose stack     at ChildProcess.emit (events.js:213:7)
14 verbose stack     at maybeClose (internal/child_process.js:897:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:208:5)
15 verbose pkgid [email protected]
16 verbose cwd C:\Users\ABC\WebstormProjects\ucowsapp
17 verbose Windows_NT 10.0.14393
18 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev" "–scripts-prepend-node-path=auto"
19 verbose node v8.1.3
20 verbose npm  v5.0.3
21 error code ELIFECYCLE
22 error errno 1
23 error [email protected] dev: `cross-env NODE_ENV=development webpack-dev-server –inline –hot –progress`
23 error Exit status 1
24 error Failed at the [email protected] dev script.
24 error This is probably not a problem with npm. There is likely additional logging output above.
25 verbose exit [ 1, true ]

Can’t build with cross-env – Error: spawn webpack ENOENT · Issue #9 · react-toolbox/react-toolbox-example

starter.js throws ‘spawn webpack-dev-server ENOENT’ error on Windows 10 · Issue #8 · react-photonkit/epp

node.js – Webpack – webpack-dev-server: command not found – Stack Overflow

win-spawn

Made spawn compatible with Windows 10 by Yolandavdvegt · Pull Request #9 · react-photonkit/epp

试了:

npm install -g webpack-dev-server

还是不行。

error spawn cmd enoent windows webpack-dev-server

spawn error on startup (Windows 7) · Issue #57 · FormidableLabs/webpack-dashboard

ForbesLindesay-Unmaintained/win-spawn: Spawn for node.js but in a way that works regardless of which OS you’re using

IndigoUnited/node-cross-spawn: A cross platform solution to node’s spawn and spawnSync

– Fixes windows by using cross-spawn, closes #57, #62 · FormidableLabs/webpack-dashboard@d57fa0d

Child Process | Node.js v8.2.1 Documentation

虽然知道了,换用:

cross-spawn或cross-spawn-async

但是:

此处实际上已经有依赖了:

另外,主要是:

此处没有别人的starter.js之类的文件,没法把

cross-spawn

加入到项目里,不知道加到哪里啊

preact-biolerplate spawn webpack-dev-server ENOENT

cross-env: command not found · Issue #493 · react-boilerplate/react-boilerplate

Error during fresh `npm run` · Issue #467 · react-boilerplate/react-boilerplate

`Error: spawn ENOENT` when executing a program installed globally via npm (Windows) · Issue #5841 · nodejs/node-v0.x-archive

cross-env webpack-dev-server

cross-env

Most Windows command prompts will choke when you set environment variables with NODE_ENV=production like that. (The exception is Bash on Windows, which uses native Bash.) Similarly, there’s a difference in how windows and POSIX commands utilize environment variables. With POSIX, you use: $ENV_VAR and on windows you use %ENV_VAR%.

kentcdodds/cross-env: Cross platform setting of environment scripts

使用cross-env解决跨平台设置NODE_ENV的问题 – 不挑食的程序员 – SegmentFault

Webpack 配置 React 开发环境 – 简书

javascript – Passing the NODE_ENV value using Webpack via DefinePlugin – Stack Overflow

cross-env webpack-dev-server notFoundError enoent.js

windows10 cross-env webpack-dev-server notFoundError enoent.js

Error: spawn node_modules/webpack/bin/webpack.js ENOENT

“I fixed mine here… install the latest node.js or LTS 6 above version…then delete your node_modules , and then install back using npm install , then you can now npm run dev.. with no error.”

windows 10 node

Installing Node.js (and npm) on Windows 10 – Stack Overflow

windows 10 npm

如何在 Windows 10 中搭建 Node.js 环境? – CNode技术社区

Download | Node.js

node js npm 关系

nodejs和npm关系 – weiyastory的博客 – CSDN博客

【总结】

最终是:

之前是由于:

> cross-env NODE_ENV=development webpack-dev-server –inline –hot –progress
  0% compiling
10% building modules 1/1 modules 0 activeevents.js:182
      throw er; // Unhandled ‘error’ event
      ^
Error: listen EADDRINUSE 127.0.0.1:8080
    at Object.exports._errnoException (util.js:1022:11)
    at exports._exceptionWithHostPort (util.js:1045:20)
    at Server.setupListenHandle [as _listen2] (net.js:1315:14)
    at listenInCluster (net.js:1363:12)
    at GetAddrInfoReqWrap.doListen (net.js:1489:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:96:10)
events.js:182
      throw er; // Unhandled ‘error’ event
      ^

所以建议去杀掉node进程:

killall node

但是其windows10中不知何故,没有生效。

然后后来其自己试试,关闭掉之前被占用的8080端口后,然后好像就可以正常执行上述的:

cross-env NODE_ENV=development webpack-dev-server –inline –hot –progress

了。

即:

此处的

Error: spawn webpack-dev-server ENOENT

竟然是由于前面的8080端口被占用而导致的?

很是诡异。

而杀掉之前占用的8080端口的程序,重新运行:

npm run dev

(内部对应着:cross-env NODE_ENV=development webpack-dev-server –inline –hot —progress)

然后就可以了。

转载请注明:在路上 » 【已解决】Windows 10中ReactJS项目npm run dev出错:Error: spawn webpack-dev-server ENOENT

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
89 queries in 0.178 seconds, using 22.09MB memory