【问题标题】:Node.js - "Uncaught Error: Cannot find module "redis""Node.js -“未捕获的错误:找不到模块“redis””
【发布时间】:2012-08-30 13:33:06
【问题描述】:

我正在尝试在使用 Redis 作为数据库的 Node.js 中 build a simple "Twitter" style short messaging app(尽管我听说 MongoDB 可能更容易)...

我找到了一些指向https://github.com/mranney/node_redis 方向的链接,因此我使用 Brunch 设置了一个新的 Node.js 项目,并按照说明在我的项目目录中运行以下内容:

npm install redis hiredis

然后我将 auth.js 示例中的以下内容添加到 vendor/script.js

var redis  = require("redis"),
client = redis.createClient();

但是,当我运行 brunch w -s 时,我在控制台中收到以下错误:

Uncaught Error: Cannot find module "redis"

我假设这与未包含在我的项目中的模块有关,但我不确定从哪里开始。我加了

"redis": "latest"

到我的 package.json 文件,但这似乎没有做任何事情。

我也尝试通过运行全局安装redis模块

sudo npm install -g redis

但还是没有运气。

我还应该补充一点,我在 OS X 上安装了 redis-server,我可以在终端中运行它:

$ redis-server
[2221] 17 Aug 10:48:42 # Warning: no config file specified, using the default config. In     order to specify a config file use 'redis-server /path/to/redis.conf'
[2221] 17 Aug 10:48:42 * Server started, Redis version 2.4.13
[2221] 17 Aug 10:48:42 * The server is now ready to accept connections on port 6379
[2221] 17 Aug 10:48:42 - 0 clients connected (0 slaves), 922304 bytes in use
[2221] 17 Aug 10:48:47 - 0 clients connected (0 slaves), 922304 bytes in use

我的应用程序目录是标准的早午餐安装 -

app
config.coffee
generators
node_modules
package.json
public
README.md
test
vendor

我做错了什么?

【问题讨论】:

  • 你的项目目录的node_modules子目录下有哪些子目录和文件?他们是否拥有正确的权限和所有者?
  • 这似乎一切正常。你能require()该目录中的任何其他模块吗?
  • @ebohlman 啊,不,我不能。尝试要求其他错误时遇到相同的错误。
  • @ebohlman 我不知道为什么我不能要求 node_modules 中的东西。在空白安装早午餐(“brunch new projectname”)上也试过这个,我仍然得到错误。

标签: javascript node.js redis brunch


【解决方案1】:

Brunch 是 html5 应用程序组装器,而不是 node.js,你不能在那里需要节点模块。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-24
    • 2015-11-22
    • 2018-12-01
    • 1970-01-01
    • 2022-10-25
    • 2022-08-13
    • 2016-07-11
    • 2016-10-24
    相关资源
    最近更新 更多