2012-04-10 69 views
1

我想在node.js应用程序中使用jQuery。根据Can I use jQuery with Node.js?,似乎很容易,但是当我试图运行npm install jQuery jsdom htmlparser xmlhttprequest和简单npm install jQuery似乎没有人为我工作。以下是错误消息我得到的全文:错误消息当试图安装jQuery与node.js

$ npm install jQuery jsdom htmlparser xmlhttprequest 
npm http GET https://registry.npmjs.org/htmlparser 
npm http GET https://registry.npmjs.org/jQuery 
npm http GET https://registry.npmjs.org/xmlhttprequest 
npm http GET https://registry.npmjs.org/jsdom 
npm http 304 https://registry.npmjs.org/jsdom 
npm http 304 https://registry.npmjs.org/htmlparser 
npm http 304 https://registry.npmjs.org/xmlhttprequest 
npm http 200 https://registry.npmjs.org/jQuery 
npm http GET https://registry.npmjs.org/contextify 
npm http GET https://registry.npmjs.org/cssom 
npm http GET https://registry.npmjs.org/request 
npm http 304 https://registry.npmjs.org/contextify 
npm http 304 https://registry.npmjs.org/cssom 
npm http 304 https://registry.npmjs.org/request 
npm http GET https://registry.npmjs.org/bindings 
npm http 304 https://registry.npmjs.org/bindings 

> [email protected] install /Users/nicmeiring/node_modules/jsdom/node_modules/contextify 
> node-gyp rebuild 

info it worked if it ends with ok 
spawn python [ '/Users/nicmeiring/.node-gyp/0.6.14/tools/gyp_addon', 
    'binding.gyp', 
    '-I/Users/nicmeiring/node_modules/jsdom/node_modules/contextify/build/config.gypi', 
    '-f', 
    'make' ] 
ERR! Error: not found: make 
    at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:43:28) 
    at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:46:29) 
    at Object.oncomplete (/usr/local/lib/node_modules/npm/node_modules/which/which.js:57:16) 
ERR! not ok 
npm WARN optional dependency failed, continuing [email protected] 
[email protected] ./node_modules/xmlhttprequest 
[email protected] ./node_modules/jquery 
[email protected] ./node_modules/htmlparser 
[email protected] ./node_modules/jsdom 
├── [email protected] 
└── [email protected] 

在我的Node.js应用程序文件(app.js)我包括使用var $ = require('jQuery) jquery的模块,但是,正如所料,它返回一个错误,当我尝试在我的应用程序中使用jQuery。任何想法是什么导致安装失败?谢谢

更新: jquery模块已成功安装,但是当我尝试运行我的应用程序时出现新错误。下面是脚本:

app.js

var express = require('express') 
    , routes = require('./routes') 
    , $ = require('jquery'); 

var app = module.exports = express.createServer(); 

// Configuration 

app.configure(function(){ 
    app.set('views', __dirname + '/views'); 
    app.set('view engine', 'jade'); 
    app.use(express.bodyParser()); 
    app.use(express.methodOverride()); 
    app.use(require('stylus').middleware({ src: __dirname + '/public' })); 
    app.use(app.router); 
    app.use(express.static(__dirname + '/public')); 

}); 

app.configure('development', function(){ 
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true })); 
}); 

app.configure('production', function(){ 
    app.use(express.errorHandler()); 
}); 

// Routes 

app.get('/', routes.index); 
app.get('/', routes.getData); 

app.listen(4000); 
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env); 

和index.js

var $ = require('jquery'); 

exports.index = function(req, res){ 
    console.log("rendering index.html") 
    res.render('layout', { title: 'Express' }) 
}; 


var link = "http://en.wikipedia.org/w/api.php?action=parse&format=json&callback=?" 

exports.getData = $.ajax({ 
         url: link, 
         dataType: JSON, 
         data: data, 
         success: function(data) { 
         console.log(data); 
         console.log(data.parse.text['*']); 
         } 
}); 

,这里是我得到的错误,当我启动应用程序

Nic-Meirings-MacBook-Pro:Wiki2 nicmeiring$ node app 

node.js:201 
     throw e; // process.nextTick error, or 'error' event on first tick 
      ^
ReferenceError: $ is not defined 
    at Object.<anonymous> (/Users/nicmeiring/Sites/Wiki2/routes/index.js:16:19) 
    at Module._compile (module.js:441:26) 
    at Object..js (module.js:459:10) 
    at Module.load (module.js:348:31) 
    at Function._load (module.js:308:12) 
    at Module.require (module.js:354:17) 
    at require (module.js:370:17) 
    at Object.<anonymous> (/Users/nicmeiring/Sites/Wiki2/app.js:7:14) 
    at Module._compile (module.js:441:26) 
    at Object..js (module.js:459:10) 
+0

当你输入“make”来安慰,你怎么看?这适用于我的Ubuntu和Node 0.6.14 – Mustafa 2012-04-10 22:44:56

+0

我应该在哪里输入“make” – 2012-04-10 22:56:37

+0

到您正在输入的地方npm install ...? – Mustafa 2012-04-10 22:57:57

回答

2

看来你缺少开发者工具附带的“make”。下面是相关的SO问题:

https://stackoverflow.com/a/1470005/337504

+0

谢谢。虐待检查出来。我应该从developer.apple.com下载什么? – 2012-04-10 23:08:07

+0

我不是一个mac用户,但它似乎:https://developer.apple.com/technologies/tools/ – Mustafa 2012-04-10 23:25:24

+0

确定谢谢你看看。你会介意查看我上面更新的代码吗? – 2012-04-10 23:27:04