Node.js 应用程序在本地运行,但 heroku 说缺少模块 [英] Node.js app works locally but heroku says missing module

查看:24
本文介绍了Node.js 应用程序在本地运行,但 heroku 说缺少模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Node.JS 和 Socket.IO 制作了一个简单的聊天应用程序,在本地一切正常,但是当我将它推送到 heroku 时,它给了我一个应用程序错误,当我检查日志时,这是错误:

I made a simple chat application using Node.JS and Socket.IO, everything works fine locally, but when I push it to heroku it gives me an application error, when I check the logs, this is the error:

Error: Cannot find module 'indexof'
    at Function.Module._resolveFilename <module.js:338:15>
    at Function.Module._load <module.js:280:25>
    at Module.require <module.js:364:17>
    at require <module.js:380:17>
    at Object.<anonymous> </app/node_modules/socket.io/node_modules/socket.io-parser/node_modules/emitter/index.js:6:13>
    at Module._compile <module.js:456:26>
    at Object.Module._extensions..js <module.js:474:10>
    at Module.load <module.js:356:32>
    at Functin.Module._load <module.js:312:12>
    at Module.require <module.js:364:17>

所以我发现 indexof 是 Socket.IO 使用的一个模块,它在我的 node_modules 文件夹中,但由于某种原因它没有被推送到 heroku 或者只是没有被识别.我重新安装了我的模块 5-6 次并重新创建了应用程序,但它仍然给我同样的错误.我的 package.json 文件有 3 个依赖项:Express、Socket.IO 和 Jade

So I figured out that indexof is a module that Socket.IO uses, and it is in my node_modules folder, but for some reason either it's not being pushed to heroku or it's just not being recognized. I reinstalled my modules 5-6 times and recreated the app but it's still giving me the same error. My package.json file has 3 dependencies: Express, Socket.IO and Jade

推荐答案

好吧,所以在 2 小时后我想通了问题,包含 indexof 模块的多个名为emitter"的文件夹也有一个 gitignore 文件,该文件使 git 忽略该模块,不知道为什么会这样,但删除它们解决了问题

Alright so after 2 hours I figured the problem out, multiple folders named "emitter" that contained the indexof module also had a gitignore file that made git ignore the module, no idea why that was even there, but deleting them fixed the problem

这篇关于Node.js 应用程序在本地运行,但 heroku 说缺少模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆