0

これがhaml-coffeeガイドに従った私のapp.jsファイルです:

// misc requirements
var express = require('express')
  , routes = require('./routes')
  , http = require('http')
  , path = require('path');

// setup app
var app = express();

// set default engine to haml-coffee
app.engine( 'hamlc', require('haml-coffee'.__express ));

// configure misc stuff
app.configure(function(){
  app.set('port', process.env.PORT || 3000); // set localhost port to 3000
  app.set('views', __dirname + '/views');    // setup views (templates)
  app.set('view engine', 'hamlc');           // use haml-coffee as default templating engine
  app.set('title', 'Learn Some Code');       // set the website title

  app.use(express.favicon());                // favicon handling
  app.use(express.logger('dev'));            // logging

  app.use(express.bodyParser());
  app.use(express.methodOverride());

  app.use(app.router); // use the router
  app.use(express.static(path.join(__dirname, 'public')));
});

// only configure this for development
app.configure('development', function(){
  app.use(express.errorHandler());
});

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

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

しかし、実行するとnode app.js...この奇妙なエラーが発生します:

module.js:236
  var start = request.substring(0, 2);
                      ^
TypeError: Cannot call method 'substring' of undefined
    at Function.Module._resolveLookupPaths (module.js:236:23)
    at Function.Module._resolveFilename (module.js:328:31)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (/Users/chris/src/learnsomecode/app.js:11:22)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
4

1 に答える 1

2

あなたのrequireにはわずかなタイプミスがあります。変化する

app.engine( 'hamlc', require('haml-coffee'.__express ));

app.engine( 'hamlc', require('haml-coffee').__express );

'haml-coffee'.__expressに解決されundefined、エラーがrequire(undefined)スローされCannot call method 'substring' of undefinedます。

于 2012-08-26T17:44:24.873 に答える