简体   繁体   中英

Heroku Node.js error code H10 "App crashed"

I just started learning NodeJS and tryied to deploy it to heroku. When I try using 'heroku open' this log happened.

 2020-10-08T14:19:52.778660+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32) 2020-10-08T14:19:52.778661+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14) 2020-10-08T14:19:52.778661+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) { 2020-10-08T14:19:52.778662+00:00 app[web.1]: code: 'MODULE_NOT_FOUND', 2020-10-08T14:19:52.778662+00:00 app[web.1]: requireStack: [ '/app/index.js' ] 2020-10-08T14:19:52.778663+00:00 app[web.1]: } 2020-10-08T14:19:52.810513+00:00 app[web.1]: npm ERR! code ELIFECYCLE 2020-10-08T14:19:52.811098+00:00 app[web.1]: npm ERR! errno 1 2020-10-08T14:19:52.828543+00:00 app[web.1]: npm ERR! nodejs_crashcourse@1.0.0 prestart: `node index` 2020-10-08T14:19:52.828751+00:00 app[web.1]: npm ERR! Exit status 1 2020-10-08T14:19:52.829002+00:00 app[web.1]: npm ERR! 2020-10-08T14:19:52.829206+00:00 app[web.1]: npm ERR! Failed at the nodejs_crashcourse@1.0.0 prestart script. 2020-10-08T14:19:52.829406+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 2020-10-08T14:19:52.847042+00:00 app[web.1]: 2020-10-08T14:19:52.847382+00:00 app[web.1]: npm ERR! A complete log of this run can be found in: 2020-10-08T14:19:52.847546+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-10-08T14_19_52_830Z-debug.log 2020-10-08T14:19:52.945200+00:00 heroku[web.1]: Process exited with status 1 2020-10-08T14:19:52.999786+00:00 heroku[web.1]: State changed from starting to crashed 2020-10-08T15:48:09.000458+00:00 heroku[web.1]: State changed from crashed to starting 2020-10-08T15:48:11.710414+00:00 heroku[web.1]: Starting process with command `npm start` 2020-10-08T15:48:14.879546+00:00 app[web.1]: 2020-10-08T15:48:14.879557+00:00 app[web.1]: > nodejs_crashcourse@1.0.0 prestart /app 2020-10-08T15:48:14.879558+00:00 app[web.1]: > node index 2020-10-08T15:48:14.879558+00:00 app[web.1]: 2020-10-08T15:48:15.028554+00:00 app[web.1]: internal/modules/cjs/loader.js:960 2020-10-08T15:48:15.028556+00:00 app[web.1]: throw err; 2020-10-08T15:48:15.028556+00:00 app[web.1]: ^ 2020-10-08T15:48:15.028557+00:00 app[web.1]: 2020-10-08T15:48:15.028557+00:00 app[web.1]: Error: Cannot find module 'nodemon' 2020-10-08T15:48:15.028557+00:00 app[web.1]: Require stack: 2020-10-08T15:48:15.028558+00:00 app[web.1]: - /app/index.js 2020-10-08T15:48:15.028559+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15) 2020-10-08T15:48:15.028559+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:840:27) 2020-10-08T15:48:15.028560+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19) 2020-10-08T15:48:15.028560+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18) 2020-10-08T15:48:15.028561+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:15:17) 2020-10-08T15:48:15.028561+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30) 2020-10-08T15:48:15.028562+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) 2020-10-08T15:48:15.028562+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32) 2020-10-08T15:48:15.028562+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14) 2020-10-08T15:48:15.028563+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) { 2020-10-08T15:48:15.028563+00:00 app[web.1]: code: 'MODULE_NOT_FOUND', 2020-10-08T15:48:15.028564+00:00 app[web.1]: requireStack: [ '/app/index.js' ] 2020-10-08T15:48:15.028564+00:00 app[web.1]: } 2020-10-08T15:48:15.045283+00:00 app[web.1]: npm ERR! code ELIFECYCLE 2020-10-08T15:48:15.045797+00:00 app[web.1]: npm ERR! errno 1 2020-10-08T15:48:15.055020+00:00 app[web.1]: npm ERR! nodejs_crashcourse@1.0.0 prestart: `node index` 2020-10-08T15:48:15.055328+00:00 app[web.1]: npm ERR! Exit status 1 2020-10-08T15:48:15.055591+00:00 app[web.1]: npm ERR! 2020-10-08T15:48:15.055865+00:00 app[web.1]: npm ERR! Failed at the nodejs_crashcourse@1.0.0 prestart script. 2020-10-08T15:48:15.056088+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 2020-10-08T15:48:15.066474+00:00 app[web.1]: 2020-10-08T15:48:15.066992+00:00 app[web.1]: npm ERR! A complete log of this run can be found in: 2020-10-08T15:48:15.067250+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-10-08T15_48_15_057Z-debug.log 2020-10-08T15:48:15.168797+00:00 heroku[web.1]: Process exited with status 1 2020-10-08T15:48:15.225575+00:00 heroku[web.1]: State changed from starting to crashed 2020-10-08T15:48:15.228118+00:00 heroku[web.1]: State changed from crashed to starting 2020-10-08T15:48:18.092770+00:00 heroku[web.1]: Starting process with command `npm start` 2020-10-08T15:48:22.002464+00:00 app[web.1]: 2020-10-08T15:48:22.002544+00:00 app[web.1]: > nodejs_crashcourse@1.0.0 prestart /app 2020-10-08T15:48:22.002550+00:00 app[web.1]: > node index 2020-10-08T15:48:22.002551+00:00 app[web.1]: 2020-10-08T15:48:22.164769+00:00 app[web.1]: internal/modules/cjs/loader.js:960 2020-10-08T15:48:22.164771+00:00 app[web.1]: throw err; 2020-10-08T15:48:22.164771+00:00 app[web.1]: ^ 2020-10-08T15:48:22.164772+00:00 app[web.1]: 2020-10-08T15:48:22.164772+00:00 app[web.1]: Error: Cannot find module 'nodemon' 2020-10-08T15:48:22.164772+00:00 app[web.1]: Require stack: 2020-10-08T15:48:22.164773+00:00 app[web.1]: - /app/index.js 2020-10-08T15:48:22.164794+00:00 app[web.1]: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:957:15) 2020-10-08T15:48:22.164795+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:840:27) 2020-10-08T15:48:22.164801+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:1019:19) 2020-10-08T15:48:22.164801+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:77:18) 2020-10-08T15:48:22.164801+00:00 app[web.1]: at Object.<anonymous> (/app/index.js:15:17) 2020-10-08T15:48:22.164802+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1133:30) 2020-10-08T15:48:22.164802+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) 2020-10-08T15:48:22.164802+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:977:32) 2020-10-08T15:48:22.164803+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:877:14) 2020-10-08T15:48:22.164812+00:00 app[web.1]: at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:74:12) { 2020-10-08T15:48:22.164823+00:00 app[web.1]: code: 'MODULE_NOT_FOUND', 2020-10-08T15:48:22.164823+00:00 app[web.1]: requireStack: [ '/app/index.js' ] 2020-10-08T15:48:22.164824+00:00 app[web.1]: } 2020-10-08T15:48:22.214230+00:00 app[web.1]: npm ERR! code ELIFECYCLE 2020-10-08T15:48:22.214698+00:00 app[web.1]: npm ERR! errno 1 2020-10-08T15:48:22.224614+00:00 app[web.1]: npm ERR! nodejs_crashcourse@1.0.0 prestart: `node index` 2020-10-08T15:48:22.224863+00:00 app[web.1]: npm ERR! Exit status 1 2020-10-08T15:48:22.225157+00:00 app[web.1]: npm ERR! 2020-10-08T15:48:22.225473+00:00 app[web.1]: npm ERR! Failed at the nodejs_crashcourse@1.0.0 prestart script. 2020-10-08T15:48:22.225688+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 2020-10-08T15:48:22.236263+00:00 app[web.1]: 2020-10-08T15:48:22.236699+00:00 app[web.1]: npm ERR! A complete log of this run can be found in: 2020-10-08T15:48:22.236908+00:00 app[web.1]: npm ERR! /app/.npm/_logs/2020-10-08T15_48_22_226Z-debug.log 2020-10-08T15:48:22.378922+00:00 heroku[web.1]: Process exited with status 1 2020-10-08T15:48:22.443106+00:00 heroku[web.1]: State changed from starting to crashed 2020-10-08T15:48:23.480249+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nameless-anchorage-18480.herokuapp.com request_id=11b5f46a-aeb7-4a22-aa83-87d815a763ba fwd="114.124.170.141" dyno= connect= service= status=503 bytes= protocol=https 2020-10-08T15:48:24.761780+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nameless-anchorage-18480.herokuapp.com request_id=41ce56e1-5274-47ef-80a7-bf712b681836 fwd="114.124.170.141" dyno= connect= service= status=503 bytes= protocol=https 2020-10-08T15:55:05.602396+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nameless-anchorage-18480.herokuapp.com request_id=c04fbdb5-e9ac-48fd-bc76-48b125727fd2 fwd="114.124.178.60" dyno= connect= service= status=503 bytes= protocol=https 2020-10-08T15:55:06.230385+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nameless-anchorage-18480.herokuapp.com request_id=87220f0f-1ae0-4f91-82f4-832bebfc59f0 fwd="114.124.178.60" dyno= connect= service= status=503 bytes= protocol=https 2020-10-08T15:56:44.427873+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=nameless-anchorage-18480.herokuapp.com request_id=cf47f697-a1ca-49d5-81c6-7bebeb363739 fwd="114.124.178.60" dyno= connect= service= status=503 bytes= protocol=https 2020-10-08T15:56:44.988746+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=nameless-anchorage-18480.herokuapp.com request_id=3c72b009-f912-4de6-9e5c-800a8936386d fwd="114.124.178.60" dyno= connect= service= status=503 bytes= protocol=https

I searched online for solutions and have tried these solutions:

  • heroku restart
  • use process.env.PORT
  • npm clean cache
  • checked that I am in master branch
  • added engine with correct version
  • Use "scripts": { "start": "node index.js" }

None of these seems to work. Here is my package.json:

 { "name": "nodejs_crashcourse", "version": "1.0.0", "engines": { "node": "12.16.3", "npm": "6.14.8" }, "description": "Node Crash Course", "main": "index.js", "scripts": { "start": "node index", "dev": "nodemon index" }, "repository": { "type": "git", "url": "git+https://github.com/nodejs_crashcourse.git" }, "keywords": [ "nodejs", "crashcourse" ], "author": "Me", "license": "ISC", "bugs": { "url": "https://github.com" }, "homepage": "https://github.com", "dependencies": { "uuid": "^8.3.1" }, "devDependencies": { "nodemon": "^2.0.4" } }

and here is my index.js:

 const http = require("http"); const path = require("path"); const fs = require("fs"); const nodemon = require("nodemon"); const server = http.createServer((req, res) => { // Build file path let filePath = path.join( __dirname, "public", req.url === "/" ? "index.html" : req.url ); // Get extension of the file let extname = path.extname(filePath); // Initial content type let contentType = "text/html"; // Check ext and set content type switch (extname) { case ".js": contentType = "text/javascript"; break; case ".css": contentType = "text/css"; break; case ".json": contentType = "application/json"; break; case ".png": contentType = "image/png"; break; case ".jpg": contentType = "image/jpg"; break; } // Read file fs.readFile(filePath, (err, content) => { if (err) { // Page not found error if (err.code == "ENOENT") { fs.readFile( path.join(__dirname, "public", "404.html"), (err, content) => { res.writeHead(200, { "Content-Type": "text/html" }); res.end(content, "utf8"); } ); } else { // Other server error res.writeHead(500); res.end(`Server Error: ${err.code}`); } } else { // Success res.writeHead(200, { "Content-Type": contentType }); res.end(content, "utf8"); } }); }); //Check if environment variable exists and if not set 5000 as default const port = process.env.PORT || 5000; server.listen(port, () => { console.log("App is running on port " + port); });

I think the problem is the const nodemon = require("nodemon"); line. Just delete it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM