Node.js找不到任何模块 [英] Node,js doesn´t find any modules

查看:129
本文介绍了Node.js找不到任何模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一个节点守卫示例,但是我发现有问题.我要遵循的示例是:

I am trying to do one of the node-horseman examples, but I am finding with a problem. The example I am trying to follow is this:

var Horseman = require('node-horseman');
var horseman = new Horseman();

var numLinks = horseman
  .open('http://www.google.com')
  .type('input[name="q"]', 'github')
  .click("button:contains('Google Search')")
  .waitForNextPage()
  .count("li.g");

console.log("Number of links: " + numLinks);

horseman.close();

当我制作phantomjs example.js时会引发以下错误:

And the errors it throws when I make phantomjs example.js are these:

Error: Cannot find module 'http'

  phantomjs://bootstrap.js:299 in require
  phantomjs://bootstrap.js:263 in require
  :3
Error: Cannot find module 'tty'

  phantomjs://bootstrap.js:299 in require
  phantomjs://bootstrap.js:263 in require
  :6
TypeError: Object is not a constructor (evaluating 'require('debug')('horseman')')

  :5
TypeError: Object is not a constructor (evaluating 'new Horseman()')

  phant.js:2 in global code

我尝试使用npm install http在本地安装http,但是在此之后,example/node_modules/http上只有package.json,如果我在此位置使用npm install,则会抛出三个警告:

I try to install http locally using npm install http, but after this, there is only a package.json on example/node_modules/http, and if I use npm install in this location, it throws three warnings:

  • 它也是核心模块的名称
  • 没有描述
  • 没有存储库字段

关于tty,进行本地安装会引发404错误.

About tty, making a local installation it throws a 404 error.

我尝试此解决方案(在路径上包括npm文件夹) Nodejs找不到模块,但是它没有用.

I try this solution (include npm folder on the path) Nodejs Cannot find module but it didn´t work.

有什么建议吗?

谢谢.

编辑 无法解决

当我从nodejs网站尝试以下简单示例时,我重新安装了node(现在我的版本是node 0.12.3,npm 2.9.1和phantomjs 1.9.8):

I reinstall node (now my version is node 0.12.3, npm 2.9.1, and phantomjs 1.9.8), when I try this simple example from the nodejs web:

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');

如果我运行"node example.js",它可以工作,但是如果我运行"phantomjs example.js",则问题仍然存在:找不到模块http".

And if I run "node example.js" it works, but if I do "phantomjs example.js" the problem persists "Cannot find module http".

我尝试通过npm("npm install -g phantomjs")并通过在其Web上下载zip,解压缩并将路径添加到解压缩文件夹的方式来安装phantomjs.

I tried install phantomjs via npm ("npm install -g phantomjs") and via downloading the zip on their web, unzipping and adding to the PATH the route to unzipped folder.

我的另一个数据是Windows 8.1.(也许有帮助).

One more data (maybe could be a help) my SO is Windows 8.1.

重新编辑

我正在观看我已安装节点的文件夹上,node_modules上唯一的文件夹是npm,对吗?在C:\ Users \ Eloy \ AppData \ Roaming上,我有两个npm文件夹,其中一个是npm-cache,另一个是npm.

I am watching that on the folder where I have installed node, the only folder on node_modules is npm, is it right?? And on C:\Users\Eloy\AppData\Roaming I have two npm folders, one of them is npm-cache and the other one simply npm. The node_modules of this last one doesn´t contain the http module, the npm-cache has a lot of modules and http incluiding... is it important??

谢谢.

推荐答案

+1第一次编辑时就观察到结果,即脚本运行时$ phantomjs无法通过require()访问全局模块,但是它可以访问本地模块.不确定这是否是phantomjs的已记录缺点

+1 your observation in first EDIT i.e scripts run like $ phantomjs can't access global modules via require(), it can access local modules though. Not sure if this is a documented shortcoming of phantomjs

这篇关于Node.js找不到任何模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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