我正在尝试设置一个 nodejs 项目以使用 requirejs。我调用我的程序,node r.js ./config/main.js
我的 main.js 如下所示:
var cs = require("coffee-script");
var requirejs = require("requirejs");
requirejs.config({
nodeRequire: require,
baseUrl: ".",
paths: {
cs: "cs",
CoffeeScript: "CoffeeScript",
csBuild: "csBuild",
express: "express",
nohm: "nohm",
redback: "redback",
_: "underscore",
"connect-redis": "connect-redis",
freebase: "freebase"
}
});
console.log("hetet");
requirejs(["cs!./config/app"], function(app){
console.log("closing")
});
在 app.coffee 里面:
define((require) ->
express = require("express")
RedisStore = require("connect-redis")(express)
app = express.createServer()
config = require('cs!./config')
require('cs!./setup')(app, express, RedisStore)
require('cs!./routes')(app)
require('cs!../src/server')
app.listen(config.server.port)
)
我似乎在 main.js 中失败并出现错误:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Calling node's require("config") failed with error: Error: Calling node's require("config") failed with error: Error: Cannot find module 'config'
我注意到的是,当我注释掉该行var requirejs = require("requirejs");
(在 main.js 中)时,我走得更远并在该行RedisStore = require("connect-redis")(express)
(在 app.coffee 中)失败并出现错误:
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: undefined is not a function
at ./config/app.coffee:10:41
我在节点中配置 requirejs 时遇到了很多麻烦,任何帮助将不胜感激。
谢谢