Node js express.compiler error

无人久伴 提交于 2019-12-07 21:00:30

问题


I am currently working on an express.js Webapp, Im working off the boilerplate app that comes with MS Webmatrix. I am able to run the app on my computer but when i push to nodejitsu or use another computer from which i got the app from git i get an error preventing server start.

app.use(express.compiler({ src: __dirname + '/public', enable: ['less'] })
                ^
TypeError: Object function createApplication() {
var app = connect();
utils.merge(app, proto);
app.request = { __proto__: req };
app.response = { __proto__: res };
app.init();
return app;
} has no method 'compiler'
at Function.<anonymous> (C:\Users\hoopdog2\Desktop\afterthoughts_nodejs\serv
er.js:197:21)
at Function.app.configure (C:\Users\hoopdog2\Desktop\afterthoughts_nodejs\no
de_modules\express\lib\application.js:399:61)
at Object.<anonymous> (C:\Users\hoopdog2\Desktop\afterthoughts_nodejs\server
.js:188:5)
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)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)

The dependencies that that app uses are

"node-uuid": ">= 1.3.3",
"everyauth": ">= 0.2.29",
"nconf": ">= 0.5.1",
"express": ">= 2.5.0",
"jade": ">= 0.18.0",
"less": ">= 1.1.5",
"socket.io": ">= 0.8.7",
"connect": ">=1.8.5",
"recaptcha": ">=1.1.0"

And i am using node version 0.8.7. Any suggestions to what might be causing this error is greatly appreciated


回答1:


The compiler middleware for Express comes from the Connect framework and as of Jul 2011 Connect no longer includes compiler. So doing express.compiler(...) doesn't work anymore.

A LESS-specific middleware has been created and Express now uses that if you include it in your startup config. express -c less will add this line to the config:

  app.use(require('less-middleware')({ src: __dirname + '/public' }));

If you have an older version of Express and Connect, you can add less-middleware to your package.json and add the line above to get it working.

It works pretty much the same as the original compiler, but includes some more bells and whistles.

less-middleware project repository




回答2:


Thanks to Hector i resolved the issue. I had the wrong version of express installed and changing express to = 2.5.0 from >=2.5.0 and reinstalling dependencies has fixed the issue and i am now able to run the app. Thanks



来源:https://stackoverflow.com/questions/12055549/node-js-express-compiler-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!