我运行npm install -g cradle
并获得输出:
npm http GET https://registry.npmjs.org/cradle
.... lots of more GET's .....
cradle@0.6.3 C:\Users\...\npm\node_modules\cradle
├── 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:\node\opensthlm\server.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上使用过摇篮,它就像一个魅力,现在我在窗户上,可能与它有关吗?否则我很无能为力。有什么想法吗?
答案 0 :(得分:1)
我也在Windows上运行节点。我复制了你的代码然后发出了以下命令。
一切似乎都运行良好。 安装底座后我得到了
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
的全局安装选项克里斯托夫
P.S。根本原因似乎是npm链接无法在Windows上工作。参见
答案 1 :(得分:0)
使用以下方式安装底座:
npm install cradle
不要使用-g开关。这对我有用。
BTW:我在管理员模式下运行命令提示符。
http://prazjain.wordpress.com/2012/04/24/node-js-error-error-cannot-find-module-xyz/