错误:找不到模块'ejs' [英] Error: Cannot find module 'ejs'

查看:1011
本文介绍了错误:找不到模块'ejs'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的完整错误:

Error: Cannot find module 'ejs'
    at Function._resolveFilename (module.js:317:11)
    at Function._load (module.js:262:25)
    at require (module.js:346:19)
    at View.templateEngine (/Users/shamoon/local/node/lib/node_modules/express/lib/view/view.js:133:38)
    at Function.compile (/Users/shamoon/local/node/lib/node_modules/express/lib/view.js:65:17)
    at ServerResponse._render (/Users/shamoon/local/node/lib/node_modules/express/lib/view.js:414:18)
    at ServerResponse.render (/Users/shamoon/local/node/lib/node_modules/express/lib/view.js:315:17)
    at /Users/shamoon/Sites/soldhere.in/app.js:26:7
    at callbacks (/Users/shamoon/local/node/lib/node_modules/express/lib/router/index.js:272:11)
    at param (/Users/shamoon/local/node/lib/node_modules/express/lib/router/index.js:246:11)

我的来源代码也很简单:

My source code is also very simple:

var express = require('express');

var app = module.exports = express.createServer();

// Configuration

app.configure(function(){
  app.use(express.bodyParser());
  app.use(app.router);
  app.use(express.static(__dirname + '/public'));
});

app.set('view engine', 'ejs');
app.set('view options', {
    layout: false
});

app.get('/', function(req, res) {
  res.render('index', {
    message : 'De groeten'
  });
});

app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);

在我的文件夹中,我在node_modules中安装了ejs,我使用 npm安装ejs
所以我的问题是..什么给?我做错了什么,当我清楚地安装它时,节点找不到EJS?

In my folder, I have ejs installed in node_modules which I got using npm install ejs. so my question is.. what gives? What am I doing wrong so that node can't find EJS when I clearly have it installed?

谢谢

推荐答案

几天前我有这个完全相同的问题,无法理解。没有妥善解决问题,但这可以作为临时解决方案:

I had this exact same problem a couple of days ago and couldn't figure it out. Haven't managed to fix the problem properly but this works as a temporary fix:

上一级(app.js上方),然后执行 npm安装ejs 。它将创建一个新的node_modules文件夹,然后Express应该找到该模块。

Go up one level (above app.js) and do npm install ejs. It will create a new node_modules folder and Express should find the module then.

这篇关于错误:找不到模块'ejs'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆