简体   繁体   English

为什么不能使用Node.js中的http服务器运行本地服务器?

[英]Why can't I get a local server running using the http-server in nodejs?

Here is an image of the node_modules folder with all the packages. 这是带有所有软件包的node_modules文件夹的图像。 I am trying to run a local server to make some basic request to interact with my mobile app im developing. 我正在尝试运行本地服务器来提出一些基本要求,以与正在开发的移动应用进行交互。 I seem to have all the correct packages/dependencies installed yet I can't get the server to run. 我似乎已经安装了所有正确的程序包/依赖关系,但无法使服务器运行。 When I try to run "node http-server" on the command line it keeps outputting this error 当我尝试在命令行上运行“ node http-server”时,它会一直输出此错误

internal/modules/cjs/loader.js:583
throw err;
^

Error: Cannot find module './lib/colors'
at Function.Module._resolveFilename   (internal/modules/cjs/loader.js:581:15)
at Function.Module._load (internal/modules/cjs/loader.js:507:25)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.<anonymous>   (/Users/jordanlagrone/Desktop/nodegang/node_modules/colors/safe.js:8:14)
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)

I have installed and reinstalled nodejs about three times to no avail. 我已经安装并重新安装了nodejs大约三遍,但无济于事。 And I have that colors module install in the node_modules folder yet im getting a message saying it cannot find it? 而且我将colors模块安装在node_modules文件夹中,但是我收到一条消息说找不到它? Can anyone help point me in the right direction to getting the server working correctly? 谁能帮助我指出正确的方向,以使服务器正常工作?

I figured out the dilemma. 我解决了难题。 I had about 6 or 7 incomplete packages so the solution was to delete each of these packages, including the colors package, and install them again. 我大约有6或7个不完整的程序包,因此解决方案是删除每个程序包(包括颜色程序包),然后重新安装。 As someone who spent over 4 hours looking for an answer, I advise you to make sure all your packages are updated, complete, and if possible in the same folder for better management! 作为花费了4个小时以上的时间来寻找答案的人,我建议您确保所有软件包都已更新,完整,如果可能,请放在同一文件夹中,以便更好地进行管理!

This problem does not relate to node_modules . 此问题与node_modules不相关。 It looks like a script in internal/modules/cjs/loader.js is require internal/modules/cjs/lib/colors.js 看起来在internal/modules/cjs/loader.js是require internal/modules/cjs/lib/colors.js

You should check file internal/modules/cjs/lib/colors.js already exist? 您应该检查文件internal/modules/cjs/lib/colors.js已经存在?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM