运行node.js应用程序时出现以下类型错误
/Users/khinester/Sandboxes/zeitgeist/Blade/server.js:5
application = require("./.app/")();
^
TypeError: object is not a function
at Object.<anonymous> (/Users/khinester/Sandboxes/zeitgeist/Blade/server.js:5:35)
at Object.<anonymous> (/Users/khinester/Sandboxes/zeitgeist/Blade/server.js:21:4)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
DEBUG: Program node server exited with code 8
DEBUG: Starting child process with 'node server'
00:55:26 - compiled src/social.coffee
我的应用程序结构如下:
☺ tree -L 3 .
.
├── Cakefile
├── README.md
├── server.coffee
├── src
│ ├── config
│ │ ├── config.coffee
│ │ ├── errors.coffee
│ │ ├── i18n.coffee
│ │ ├── models.coffee
│ │ ├── passport.coffee
│ │ └── routes.coffee
│ ├── controllers
│ │ ├── api.coffee
│ │ ├── index.coffee
│ │ ├── login.coffee
│ │ ├── map.coffee
│ │ └── user.coffee
│ ├── index.coffee
│ ├── models
│ │ └── user
│ │ └── user.coffee
│ └── utils
│ ├── dbconnect.coffee
│ ├── emailer.coffee
│ ├── i18n.coffee
│ ├── logger.coffee
│ └── passport.coffee
└── views
├── 404.blade
├── 500.blade
├── footer.blade
├── forms
│ ├── federated-form.blade
│ ├── login-form.blade
│ └── registration-form.blade
├── header.blade
├── index.blade
└── user
├── create.blade
├── login.blade
└── user.blade
我的server.coffee
如下:
application = require("./.app/")()
nowjs = require "now"
port = process.env.PORT or process.env.VMC_APP_PORT or process.env.VCAP_APP_PORT or 3000
server = application.listen(port)
everyone = nowjs.initialize(server)
console.log "Server running at http://127.0.0.1: "+ port + "\nPress CTRL-C to stop server."
编译为:
// Generated by CoffeeScript 1.6.2
(function() {
var application, everyone, nowjs, port, server;
application = require("./.app/")();
nowjs = require("now");
if (!process.env.NODE_ENV) {
process.env.NODE_ENV = "local";
}
port = process.env.PORT || process.env.VMC_APP_PORT || process.env.VCAP_APP_PORT || 3000;
server = application.listen(port);
everyone = nowjs.initialize(server);
console.log("Server running at http://127.0.0.1: " + port + "\nPress CTRL-C to stop server.");
}).call(this);
和/app/index.coffee
:
#Load external dependencies
express = require("express")
stylus = require("stylus")
mongoose = require("mongoose")
i18next = require "i18next"
#Load local dependencies
models = require("./config/models")
i18n = require("./config/i18n")
config = require("./config/config")
routes = require("./config/routes")
#Load database dependencies
dbconnection = require "./utils/dbconnect"
#Load logger
logger = require "./utils/logger"
# Initialize logger
logger.configure()
logCategory = "APP config"
# Create Server
app = express()
logger.info "---- App server created ----", logCategory
#Exports
module.exports = ->
# Load Mongoose Models
models app
# Load i18next config
i18n app
# Init i18next
i18next.init(app.i18n)
i18next.registerAppHelper(app)
# Load Expressjs config
config app
# Load routes config
routes app
app
logger.info "---- Modules loaded into namespace ----", logCategory
# Connect to database
dbconnection.init (result) ->
if result
logger.info "Database initialized", logCategory
所以,每次运行应用程序时,我都会得到TypeError,但应用程序会运行!
我错过了什么,而不是在这里理解?
任何建议都非常感激。
答案 0 :(得分:0)
我有一个猜测 - 也许在编译咖啡脚本和运行js之间存在某种竞争条件?
无论哪种方式,如果我是你,我会尝试隔离问题 - 交互模式下的开放节点(或咖啡) - 需要你的应用程序代码 - 你可以调用该函数吗?它是一个功能吗?宾语? 尝试使用咖啡来运行您的应用程序而不是节点。你得到同样的错误吗?
另一件事 - 你说它在./app中,但在你的代码中它是在./.app中 - 我想这不是问题,因为会发生不同的错误。