我在練習Orelly ‘網頁應用程式應用,使用NODE和Express’ 一書 發生一個錯誤 Express started on http://localhost:3000;press Ctrl-C to terminate. Error: Cannot find module ‘[object Object]‘ at Function.Module._resolveFilename (module.js:336:15) at Function.Module._load (module.js:278:25) at Module.require (module.js:365:17) at require (module.js:384:17) at new View (/Users/antelopehi/Google 雲端硬碟/nodeExpress/projects/meadowlark/site/node_modules/express/lib/view.js:78:30) at EventEmitter.render (/Users/antelopehi/Google 雲端硬碟/nodeExpress/projects/meadowlark/site/node_modules/express/lib/application.js:569:12) at ServerResponse.render (/Users/antelopehi/Google 雲端硬碟/nodeExpress/projects/meadowlark/site/node_modules/express/lib/response.js:961:7) at /Users/antelopehi/Google 雲端硬碟/nodeExpress/projects/meadowlark/site/meadowlark.js:20:9 at Layer.handle [as handle_request] (/Users/antelopehi/Google 雲端硬碟/nodeExpress/projects/meadowlark/site/node_modules/express/lib/router/layer.js:95:5) at next (/Users/antelopehi/Google 雲端硬碟/nodeExpress/projects/meadowlark/site/node_modules/express/lib/router/route.js:131:13) 附上圖片程式碼。 app.get(’/’, function(req, res) { res.render(‘home’); }); 可能是render這邊有狀況。請求大神幫忙解決。
app.set('view engine', 'handlebars');
express v4? api的语法是: set('view engine', 'string here')
. 所以, 用app.set('view engine', 'handlebars')
试试
楼上已答, 重复了
太感謝了,原來是我語法有問題。 書上也是這樣寫。我檢查好機次都沒檢查到。謝謝
@antelopehi 这种时候, 就应该对着错误栈里提示的信息, 找express的源码看一下, 顺便学习下人家的代码, 也是一种锻炼嘛