问题
My app was working locally but when I deployed to Heroku, there was an issue. This was my error, It seems that the error was caused by something that I failed to do after I added EJS.
2014-01-06T16:53:39.285571+00:00 app[web.1]: module.js:340
2014-01-06T16:53:39.285956+00:00 app[web.1]: throw err;
2014-01-06T16:53:39.286233+00:00 app[web.1]: ^
2014-01-06T16:53:39.288439+00:00 app[web.1]: Error: Cannot find module 'ejs'
2014-01-06T16:53:39.288439+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:338:15)
2014-01-06T16:53:39.288439+00:00 app[web.1]: at Function.Module._load (module.js:280:25)
2014-01-06T16:53:39.288439+00:00 app[web.1]: at require (module.js:380:17)
2014-01-06T16:53:39.288439+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:28:20)
2014-01-06T16:53:39.288439+00:00 app[web.1]: at Module._compile (module.js:456:26)
2014-01-06T16:53:39.288439+00:00 app[web.1]: at Module.require (module.js:364:17)
2014-01-06T16:53:39.288439+00:00 app[web.1]: at Object.Module._extensions..js (module.js:474:10)
2014-01-06T16:53:39.288439+00:00 app[web.1]: at Module.load (module.js:356:32)
2014-01-06T16:53:39.288439+00:00 app[web.1]: at Function.Module._load (module.js:312:12)
2014-01-06T16:53:39.288617+00:00 app[web.1]: at Function.Module.runMain (module.js:497:10)
2014-01-06T16:53:40.650512+00:00 heroku[web.1]: State changed from starting to crashed
2014-01-06T16:53:40.637888+00:00 heroku[web.1]: Process exited with status 8
2014-01-06T16:53:40.651134+00:00 heroku[web.1]: State changed from crashed to starting
2014-01-06T16:53:42.536106+00:00 heroku[web.1]: Starting process with command `node app.js`
2014-01-06T16:53:43.447621+00:00 app[web.1]:
2014-01-06T16:53:43.449816+00:00 app[web.1]: Error: Cannot find module 'ejs'
2014-01-06T16:53:43.447621+00:00 app[web.1]: module.js:340
2014-01-06T16:53:43.447926+00:00 app[web.1]: throw err;
2014-01-06T16:53:43.447926+00:00 app[web.1]: ^
2014-01-06T16:53:43.449816+00:00 app[web.1]: at Function.Module._resolveFilename (module.js:338:15)
2014-01-06T16:53:43.449816+00:00 app[web.1]: at Function.Module._load (module.js:280:25)
2014-01-06T16:53:43.449816+00:00 app[web.1]: at Module.require (module.js:364:17)
2014-01-06T16:53:43.449816+00:00 app[web.1]: at Module._compile (module.js:456:26)
2014-01-06T16:53:43.449816+00:00 app[web.1]: at Object.Module._extensions..js (module.js:474:10)
2014-01-06T16:53:43.449816+00:00 app[web.1]: at Module.load (module.js:356:32)
2014-01-06T16:53:43.449816+00:00 app[web.1]: at Function.Module._load (module.js:312:12)
2014-01-06T16:53:43.449990+00:00 app[web.1]: at Function.Module.runMain (module.js:497:10)
2014-01-06T16:53:43.449816+00:00 app[web.1]: at require (module.js:380:17)
2014-01-06T16:53:43.449816+00:00 app[web.1]: at Object.<anonymous> (/app/app.js:28:20)
2014-01-06T16:53:44.712427+00:00 heroku[web.1]: State changed from starting to crashed
2014-01-06T16:53:44.700963+00:00 heroku[web.1]: Process exited with status 8
2014-01-06T16:54:13.976150+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=bruxzir-express.herokuapp.com fwd="98.173.1.66" dyno= connect= service= status=503 bytes=
2014-01-06T16:54:29.109297+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=bruxzir-express.herokuapp.com fwd="98.173.1.66" dyno= connect= service= status=503 bytes=
2014-01-06T16:54:29.243506+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=bruxzir-express.herokuapp.com fwd="98.173.1.66" dyno= connect= service= status=503 bytes=
After reading this question on SO I needed to add that dependency in the package.json
. And to the version of ejs I ran npm list
and got this, which looks like there might be more errors to address.
application-name@0.0.1 /Users/juan.gallardo/Desktop/myfiles/test-projects/bruxzir-express-test
├── ejs@0.8.5 extraneous
├─┬ express@3.4.4
│ ├── buffer-crc32@0.2.1
│ ├─┬ commander@1.3.2
│ │ └── keypress@0.1.0
│ ├─┬ connect@2.11.0
│ │ ├── bytes@0.2.1
│ │ ├── methods@0.0.1
│ │ ├─┬ multiparty@2.2.0
│ │ │ ├─┬ readable-stream@1.1.9
│ │ │ │ ├── core-util-is@1.0.0
│ │ │ │ └── debuglog@0.0.2
│ │ │ └── stream-counter@0.2.0
│ │ ├── negotiator@0.3.0
│ │ ├── pause@0.0.1
│ │ ├── qs@0.6.5
│ │ ├── raw-body@0.0.3
│ │ └── uid2@0.0.3
│ ├── cookie@0.1.0
│ ├── cookie-signature@1.0.1
│ ├── debug@0.7.4
│ ├── fresh@0.2.0
│ ├── methods@0.1.0
│ ├── mkdirp@0.3.5
│ ├── range-parser@0.0.4
│ └─┬ send@0.1.4
│ └── mime@1.2.11
├─┬ jade@1.0.0
│ ├── character-parser@1.2.0
│ ├── commander@2.0.0
│ ├─┬ constantinople@1.0.2
│ │ └─┬ uglify-js@2.4.8
│ │ ├── async@0.2.9
│ │ ├─┬ optimist@0.3.7
│ │ │ └── wordwrap@0.0.2
│ │ ├─┬ source-map@0.1.31
│ │ │ └── amdefine@0.1.0
│ │ └── uglify-to-browserify@1.0.1
│ ├── mkdirp@0.3.5
│ ├─┬ monocle@1.1.50
│ │ └─┬ readdirp@0.2.5
│ │ └─┬ minimatch@0.2.14
│ │ ├── lru-cache@2.5.0
│ │ └── sigmund@1.0.0
│ ├─┬ transformers@2.1.0
│ │ ├─┬ css@1.0.8
│ │ │ ├── css-parse@1.0.4
│ │ │ └── css-stringify@1.0.5
│ │ ├─┬ promise@2.0.0
│ │ │ └── is-promise@1.0.0
│ │ └─┬ uglify-js@2.2.5
│ │ ├─┬ optimist@0.3.7
│ │ │ └── wordwrap@0.0.2
│ │ └─┬ source-map@0.1.31
│ │ └── amdefine@0.1.0
│ └─┬ with@2.0.0
│ └─┬ uglify-js@2.4.0
│ ├── async@0.2.9
│ ├─┬ optimist@0.3.7
│ │ └── wordwrap@0.0.2
│ ├─┬ source-map@0.1.31
│ │ └── amdefine@0.1.0
│ └── uglify-to-browserify@1.0.1
├── simple-recaptcha@0.0.3 extraneous
└─┬ stylus@0.41.3
├── cssom@0.2.5
├── debug@0.7.4
├── mkdirp@0.3.5
└── sax@0.5.8
npm ERR! extraneous: ejs@0.8.5 /Users/juan.gallardo/Desktop/myfiles/test-projects/bruxzir-express-test/node_modules/ejs
npm ERR! extraneous: simple-recaptcha@0.0.3 /Users/juan.gallardo/Desktop/myfiles/test-projects/bruxzir-express-test/node_modules/simple-recaptcha
npm ERR! not ok code 0
回答1:
I resolved this just by listing EJS and its version into my package.json
.
"ejs": "0.8.5"
If you do not know the version of EJS that you have, the way I found mine was to run npm list
.
Here is my current entire file if you are curious how it all fits in together to deploy on heroku.
{
"name": "application-name",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node app.js"
},
"dependencies": {
"express": "3.4.4",
"jade": "*",
"stylus": "*",
"ejs": "0.8.5"
},
"engines": {
"node": "0.10.1",
"npm": "1.3.14"
}
}
来源:https://stackoverflow.com/questions/20955388/cannot-find-module-ejs-node-js-app-on-heroku