오류 : '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)
내 소스 코드도 매우 간단합니다.
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 install ejs
있습니다. 그래서 내 질문은 .. 무엇을 제공합니까? 내가 명확하게 설치했을 때 노드가 EJS를 찾을 수 없도록 내가 뭘 잘못하고 있습니까?
감사
며칠 전에 똑같은 문제가 있었는데 알아낼 수 없었습니다. 문제를 제대로 해결하지 못했지만 임시 수정으로 작동합니다.
한 단계 (app.js 이상) 위로 이동하고 npm install ejs
. 새 node_modules 폴더가 생성되고 Express가 모듈을 찾습니다.
로컬로 Express 설치
( npm install express
프로젝트의 루트 디렉토리에있는 동안)
프로젝트는 express
및 ejs
둘 다에 종속되므로 둘 다 package.json
.
이렇게 npm install
하면 프로젝트 디렉토리에서 실행할 때 express
및을 모두 설치 ejs
하므로 글로벌 설치가 아닌 Express ( 로컬에 설치 한 모듈 에 대해 알고 var express = require('express')
있음)의 로컬 설치가 ejs
됩니다.
일반적으로 package.json
일부 종속성 이 이미 전역 적으로 설치되어 있어도 이러한 유형의 문제가 발생하지 않더라도 모든 종속성을 명시 적으로 나열하는 것이 좋습니다 .
나는 같은 문제가 있었다. 환경 변수 NODE_PATH를 내 모듈의 위치 (내 경우에는 /usr/local/node-v0.8.4/node_modules)로 설정하면 문제가 사라졌습니다. PS NODE_PATH는 둘 이상을 지정해야하는 경우 콜론으로 구분 된 디렉토리 목록을 허용합니다.
제 경우에는 package.json에 수동으로 ejs를 추가했습니다 .
{
"name": "myApp"
"dependencies": {
"express": "^4.12.2",
"ejs": "^1.0.0"
}
}
그리고 npm install을 실행하십시오 ( sudo로 실행해야 할 수도 있습니다 ) ejs는 기본적으로 뷰 디렉토리를 찾습니다.
Express 디렉토리 수준에서 ejs
명령 npm install ejs
을 사용하여 설치 했는데 이로 인해 문제가 해결되었습니다.
익스프레스 가이드 http://expressjs.com/guide.html에 언급 된 단계를 사용하여 익스프레스를 설치했습니다 .
전체적으로 설치하는 대신 로컬로 설치하십시오. 그러면 프로젝트가 오류없이 모든 컴퓨터에서 실행될 수 있습니다.
npm install express --save
npm install ejs --save
--save 옵션을 사용하여 express와 ejs를 모두 설치했습니다.
npm install ejs --save npm install express --save
이런 식으로 express 및 ejs는 종속 package.json 파일입니다.
npm, express 및 ejs를 다시 설치하면 문제가 해결되었습니다.
이것은 나를 위해 일했습니다.
- 터미널 또는 cmd-> 앱 디렉토리로 이동하십시오.
- cd pathtoyourapp / AppName
- 'npm 설치'를 다시 실행하십시오.
- 'npm install express'를 다시 실행하십시오.
- 'npm install ejs'를 다시 실행하십시오.
그 후 오류가 수정되었습니다.
Express V xxx를 설치 한 후 템플릿보기 엔진을 선택해야합니다. 정말 배우기 쉬운 것이 많이 있습니다. 내 개인적인 이동은 EJS 입니다.
정말 훌륭하고 배우기 쉬운 다른 것들은 다음과 같습니다.
To install EJS (And fix your error) Run in root of your project:
npm install ejs
Or if you're using Yarn:
yarn add ejs
Next you'll need to require the module, so open up your file where you require express (usually app.js or server.js)
add below var express = require('express');
var ejs = require('ejs');
I had this problem. I debugged using node-inspector and saw that from the node_modules folder where the express source files were, ejs was not installed. So I installed it there and it worked.
npm install -g ejs
didn't put it where I expected it to despite NODE_PATH being set to the same node_modules folder. Prob doing it wrong, just started with node.
STEP 1
See npm ls | grep ejs
at root level of your project to check if you have already added ejs
dependency
to your project.
If not, add it as dependencies
to your project. (I prefer adding dependency to package.json
instead of npm install
ing the module.)
eg.
{
"name": "musicpedia",
"version": "0.0.0",
"private": true,
"scripts": {
"start": "node ./bin/www"
},
"dependencies": {
"body-parser": "~1.15.1",
"cookie-parser": "~1.4.3",
"debug": "~2.2.0",
"express": "~4.13.4",
"jade": "~1.11.0",
"ejs": "^1.0.0",
"morgan": "~1.7.0",
"serve-favicon": "~2.3.0"
}
}
STEP 2 download the dependencies
npm install
STEP 3 check ejs module
$ npm ls | grep ejs
musicpedia@0.0.0 /Users/prayagupd/nodejs-fkers/musicpedia
├── ejs@1.0.0
Add dependency in package.json
and then run npm install
{
...
...
"dependencies": {
"express": "*",
"ejs": "*",
}
}
I think ejs template engine is not properly installed on your machine. You just install the template engine using npm
npm install ejs --save
then include the following code in app.js
app.set('view engine', 'ejs')
I have the same issue it resolve after installing the express in my project directory. previously i install it in global scope with -g option with npm install command.
In my case there was no silly syntax error, but same error arised. I had installed ejs and ejs-mate globally. I installed it locally and found my error resolved.
kindly ensure that your dependencies in your package.json files are up to date. Try reinstalling them one at a time after also ensuring that your NPM is the latest version (up-to-date). It worked for me. I advise you to run npm install
for the packages(thats what worked in my own case after it refused to work because I added the dependencies manually).
In my case it was a stupid mistake- it was a typo in the middleware. I wrote app.set('view engine', 'ejs.');
the dot caused the error. I installed ejs and express locally
Way back when the same issue happened with me.
Dependency was there for ejs in JSON file, tried installing it locally and globally but did not work.
Then what I did was manually adding the module by:
app.set('view engine','ejs');
app.engine('ejs', require('ejs').__express);
Then it works.
Ensure all dependencies are installed. npm install
나는 나 자신을 위해 빠른 앱을 만들고 있었고 Express를 추가하는 것을 잊었습니다. 위의 오류를 던졌습니다.
app.set('view engine', 'ejs')
그리고 터미널에서
npm install ejs --save
문제를 해결합니다
참고 URL : https://stackoverflow.com/questions/7754799/error-cannot-find-module-ejs
'program tip' 카테고리의 다른 글
배열에 객체가 포함되어 있는지 확인하려면 어떻게합니까? (0) | 2020.10.23 |
---|---|
JAX-RS 다중 오브젝트 게시 (0) | 2020.10.23 |
Tmux의 창 제목 (0) | 2020.10.23 |
가져 오기 라이브러리는 어떻게 작동합니까? (0) | 2020.10.22 |
Sass 캐시 폴더가 생성되는 이유 (0) | 2020.10.22 |