如何诊断此错误?

时间:2016-08-19 07:23:28

标签: javascript node.js browserify

我试图运行voxel-hello-world(类似Minecraft的游戏,在浏览器中运行)。当我尝试访问localhost中的页面时出现以下错误:

4 verbose stack Error: voxel-hello-world@0.6.0 start: `beefy test.js:bundle.js 8080`
14 verbose stack Exit status 1
14 verbose stack     at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:242:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:852:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)

详细信息(包括npm-debug.log)可以找到here

我没有使用Node.js的经验。我怀疑Node.js的版本可能与此代码兼容,AFAIK是几年前写的。我尝试了几个较旧版本的Node.js,结果相同。

如何修复此错误?它的根本原因是什么?

更新1:当我运行beefy test.js:bundle.js时,我明白了:

C:\dev\voxel-hello-world>beefy test.js:bundle.js 8080
module.js:457
    throw err;
    ^

Error: Cannot find module 'C:\Users\pisarenko\Documents\dev\voxel-hello-world\node_modules\browserify/bin/args.js'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at setupBrowserify (C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\lib\bundlers\browserify.js:6:19)
    at onlocalbrowserify (C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\lib\setup-bundlers.js:30:5)
    at C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\node_modules\resolve\lib\async.js:42:21
    at C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\node_modules\resolve\lib\async.js:121:35
    at C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\node_modules\resolve\lib\async.js:93:39
    at C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\node_modules\resolve\lib\async.js:59:30

我尝试安装browserify ...

C:\Users\pisarenko\Documents\dev\voxel-hello-world>npm install browserify -g
C:\Users\pisarenko\AppData\Roaming\npm\browserify -> C:\Users\pisarenko\AppData\Roaming\npm\node_modules\browserify\bin\cmd.js
C:\Users\pisarenko\AppData\Roaming\npm
`-- browserify@13.1.0

但是同样的错误来了。

更新2:将端口更改为8085无济于事。

C:\Users\pisarenko\Documents\dev\voxel-hello-world>npm start

> voxel-hello-world@0.6.0 start C:\Users\pisarenko\Documents\dev\voxel-hello-world
> beefy test.js:bundle.js 8085

listening on 8085
using .\node_modules\.bin\browserify
200   75ms    1.08KB /index.html
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: spawn C:\Users\pisarenko\Documents\dev\voxel-hello-world\node_modules\.bin\browserify ENOENT
  at exports._errnoException (util.js:1026:11)
  at Process.ChildProcess._handle.onexit (internal/child_process.js:182:32)
  at onErrorNT (internal/child_process.js:348:16)
  at _combinedTickCallback (internal/process/next_tick.js:74:11)
  at process._tickCallback (internal/process/next_tick.js:98:9)


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" "start"
npm ERR! node v6.4.0
npm ERR! npm  v3.10.3
npm ERR! code ELIFECYCLE
npm ERR! voxel-hello-world@0.6.0 start: `beefy test.js:bundle.js 8085`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the voxel-hello-world@0.6.0 start script 'beefy test.js:bundle.js 8085'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the voxel-hello-world package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     beefy test.js:bundle.js 8085
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs voxel-hello-world
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls voxel-hello-world
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\pisarenko\Documents\dev\voxel-hello-world\npm-debug.log

C:\Users\pisarenko\Documents\dev\voxel-hello-world>

更新3:正在运行

npm install beefy
npm install browserify

没有帮助。

更新4:以下是目录voxel-hello-world\node_modules\.bin\的回复。

Screenshot

更新5:根据npm --verbose start的输出,npm尝试执行命令beefy test.js:bundle.js 8085

C:\Users\pisarenko\Documents\dev\voxel-hello-world>npm --verbose start
npm info it worked if it ends with ok
npm verb cli [ 'C:\\Program Files\\nodejs\\node.exe',
npm verb cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
npm verb cli   '--verbose',
npm verb cli   'start' ]
npm info using npm@3.10.3
npm info using node@v6.4.0
npm verb run-script [ 'prestart', 'start', 'poststart' ]
npm info lifecycle voxel-hello-world@0.6.0~prestart: voxel-hello-world@0.6.0
npm info lifecycle voxel-hello-world@0.6.0~start: voxel-hello-world@0.6.0
  

voxel-hello-world@0.6.0启动C:\ Users \ pisarenko \ Documents \ dev \ voxel-hello-world   beefy test.js:bundle.js 8085

当我尝试自己运行该命令时,它无法找到该目录中不存在的文件C:\Users\pisarenko\Documents\dev\voxel-hello-world\node_modules\browserify/bin/args.js(参见下面的屏幕截图)。

C:\Users\pisarenko\Documents\dev\voxel-hello-world>beefy test.js:bundle.js 8085
module.js:457
    throw err;
    ^

Error: Cannot find module 'C:\Users\pisarenko\Documents\dev\voxel-hello-world\node_modules\browserify/bin/args.js'
    at Function.Module._resolveFilename (module.js:455:15)
    at Function.Module._load (module.js:403:25)
    at Module.require (module.js:483:17)
    at require (internal/module.js:20:19)
    at setupBrowserify (C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\lib\bundlers\browserify.js:6:19)
    at onlocalbrowserify (C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\lib\setup-bundlers.js:30:5)
    at C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\node_modules\resolve\lib\async.js:42:21
    at C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\node_modules\resolve\lib\async.js:121:35
    at C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\node_modules\resolve\lib\async.js:93:39
    at C:\Users\pisarenko\AppData\Roaming\npm\node_modules\beefy\node_modules\resolve\lib\async.js:59:30

Screenshot 2

1 个答案:

答案 0 :(得分:4)

快速解决方法:编辑voxel-hello-world/node_modules/beefy/index.js,替换此行(第64行?):

bfy = spawn(browserify_path, args)

bfy = spawn(browserify_path, args, {shell: true})

,然后npm start,以chrome

打开它

Screenshot

我在git bash中使用以下命令重现了同样的错误:

$ git clone https://github.com/maxogden/voxel-hello-world
$ cd voxel-hello-world/
$ npm -v
3.3.6
$ node -v
v6.1.0
$ cmd /c ver
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
> exit
$ npm i
$ npm start

beefy spawns没有shell的命令行browserify,这适用于Linux,因为node_modules/.bin/browserify是有效的可执行文件。但Windows无法执行它。

添加选项{shell: true}是启动shell(cmd.exe)并在其中运行命令,browserify解析为shell中的批处理文件browserify.cmd。 / p>

不需要全局安装browserify或其他软件包,npm start和其他npm脚本会自动将本地软件包的可执行文件添加到PATH