我运行npm install -g cradle
并获得输出:
npm http GET https://registry.npmjs.org/cradle
.... lots of more GET's .....
cradle@0.6.3 C:Users...npmnode_modulescradle
├── vargs@0.1.0
├── request@2.9.153
└── follow@0.7.1
一切似乎都很顺利。
但是当我运行server.js
时
var fs = require("fs");
var express = require("express");
var site = express.createServer();
var io = require("socket.io").listen(site);
var cradle = require('cradle');
io.set('log level', 1);
// Determine which dist directory to use
var dir = process.argv.length > 2 && "./dist/" + process.argv[2];
// Use custom JS folder based off debug or release
dir && site.use("/assets/js", express.static(dir + "/js"));
dir && site.use("/assets/css", express.static(dir + "/css"));
// Serve static files
site.use("/app", express.static("./app"));
site.use("/assets", express.static("./assets"));
site.use("/dist", express.static("./dist"));
// Serve favicon.ico
site.use(express.favicon("./favicon.ico"));
// Ensure all routes go home, client side app..
site.get("*", function (req, res) {
fs.createReadStream("./index.html").pipe(res);
});
// Communication with clients
io.sockets.on('connection', function (socket) {
console.log('user connected');
socket.on('testCommunication', function (message, fn) {
fn(message + ' world');
});
});
site.listen(8000);
,我得到输出:
info - socket.io started
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'cradle'
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> (C:nodeopensthlmserver.js:6:14)
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)
该模块与socket.io、express等位于同一目录中,我在加载这些目录时没有遇到任何问题。我已经盯着这个错误看了一个小时了。我以前在mac上用过摇篮,它很有魅力,现在我在窗户上,这和它有关系吗?否则我就一无所知。有什么想法吗?
我也在Windows上运行node。我复制了你的代码,然后发出了以下命令。
- npm install express
- npm安装插座.io
- npm安装支架
- 节点服务器.js
一切似乎都很顺利。安装支架后,我得到了
npm http GET http://registry.npmjs.org/cradle
npm http 200 http://registry.npmjs.org/cradle
npm http GET http://registry.npmjs.org/follow
npm http GET http://registry.npmjs.org/vargs/0.1.0
npm http GET http://registry.npmjs.org/request
npm http 200 http://registry.npmjs.org/vargs/0.1.0
npm http GET http://registry.npmjs.org/vargs/-/vargs-0.1.0.tgz
npm http 200 http://registry.npmjs.org/follow
npm http 200 http://registry.npmjs.org/vargs/-/vargs-0.1.0.tgz
npm http 200 http://registry.npmjs.org/request
npm http GET http://registry.npmjs.org/request
npm http 200 http://registry.npmjs.org/request
cradle@0.6.3 ./node_modules/cradle
├── vargs@0.1.0
├── request@2.9.153
└── follow@0.7.2
注意,我没有使用npm1.x 的全局安装选项
克里斯托夫
附言:根本原因似乎是npm链接无法在windows上运行。参见
- http://groups.google.com/group/npm-/browse_thread/thread/13f20c6845bc90d6?pli=1
- npm链接不起作用(windows);将git和node.js用于lexandra/Aardwolf.git
- https://github.com/isaacs/npm/issues/1845
安装支架使用:
npm install cradle
不要使用-g开关。这对我很有帮助。
BTW:我在管理模式下运行了命令提示符。
http://prazjain.wordpress.com/2012/04/24/node-js-error-error-cannot-find-module-xyz/