相关疑难解决方法(0)

如何使用Node.js解决"无法找到模块"错误?

从GitHub下拉模块并按照说明构建它之后,我尝试使用以下方法将其拉入现有项目中:

> npm install ../faye
Run Code Online (Sandbox Code Playgroud)

这似乎可以解决问题:

> npm list
/home/dave/src/server
??? faye@0.7.1
  ??? cookiejar@1.3.0
  ??? hiredis@0.1.13
  ??? redis@0.7.1
Run Code Online (Sandbox Code Playgroud)

但是Node.js找不到模块:

> node app.js
node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
              ^
Error: Cannot find module 'faye'
    at Function._resolveFilename (module.js:334:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:357:17)
    at require (module.js:368:17)
    at Object.<anonymous> (/home/dave/src/server/app.js:2:12)
    at Module._compile (module.js:432:26)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Array.0 (module.js:470:10)
Run Code Online (Sandbox Code Playgroud)

我真的很想了解这里发生了什么,但我对于下一步该看哪里感到有点失落.有什么建议?

node.js

559
推荐指数
14
解决办法
144万
查看次数

如何在Node中导入全局模块?我得到"错误:找不到模块<module>"?

我正在尝试在Mac OSX Lion上设置Node.这一切似乎都运行正常,但我似乎无法从我的全局模块文件夹导入任何模块.我收到错误,

Error: Cannot find module <module>
Run Code Online (Sandbox Code Playgroud)

如果我运行这个:node -e require.paths,我得到的回应是:

[ '/usr/local/lib/node_modules',
  '/Users/Me/.node_modules',
  '/Users/Me/.node_libraries',
  '/usr/local/Cellar/node/0.4.12/lib/node' ]
Run Code Online (Sandbox Code Playgroud)

哪个是正确的,我的模块确实安装在/ usr/local/lib/node_modules中.但是,当我尝试运行脚本时,我得到了这个:

Error: Cannot find module 'socket.io'
    at Function._resolveFilename (module.js:326:11)
    at Function._load (module.js:271:25)
    at require (module.js:355:19)
    at Object.<anonymous> (/Users/Me/node/server.js:2:10)
    at Module._compile (module.js:411:26)
    at Object..js (module.js:417:10)
    at Module.load (module.js:343:31)
    at Function._load (module.js:302:12)
    at Array.<anonymous> (module.js:430:10)
    at EventEmitter._tickCallback (node.js:126:26)
Run Code Online (Sandbox Code Playgroud)

我的.bash_profile看起来像这样:

export PATH=/usr/local/mysql/bin:$PATH
export NODE_PATH=/usr/local/lib/node_modules
export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/"
Run Code Online (Sandbox Code Playgroud)

真的很感激一些帮助,我不知道为什么我不能导入任何库.

node.js npm

132
推荐指数
6
解决办法
9万
查看次数

node.js,错误:无法找到模块'express'

我是Node.js的新手,尝试学习express来构建我的第一个Web应用程序.我被困在我的第一个示例代码上,需要一些帮助才能让它运行起来.在我发布这个问题之前,我确实搜索了堆栈溢出,发现了一些类似的问题,但仍然无法修复它.

错误:找不到模块'express'

我使用的是mac os 10.8.2.我一直在使用Node.js的安装nvm.

node.js:0.8.20节点路径:/Users/feelexit/nvm/v0.8.20/bin/node要表达的路径:/ Users/feelexit/nvm/node_modules/express

这是我的示例代码:此文件位于:

/Users/feelexit/WebstormProjects/learnnode/node_modules/index.js

var express = require('express');

var app = express();

app.get('/', function(req, res){

    res.send('welcome to express');
});

app.listen(3000);
Run Code Online (Sandbox Code Playgroud)

当我尝试运行此命令时 node index.js

我收到以下错误消息,请帮我解决.

谢谢.

Error: Cannot find module 'express'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/feelexit/WebstormProjects/learnnode/node_modules/index.js:1:81)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)
feelexits-Mac:node_modules feelexit$ 
Run Code Online (Sandbox Code Playgroud)

更新回答chovy的问题:

feelexits-Mac:~ feelexit$ npm install
npm ERR! install Couldn't …
Run Code Online (Sandbox Code Playgroud)

node.js express

106
推荐指数
8
解决办法
22万
查看次数

标签 统计

node.js ×3

express ×1

npm ×1