Getting "npm start" error when deploy Node JS app to Heroku server

4.4k Views Asked by At

I'm getting this error when i deploy my NodeJS app to Heroku server.

2019-08-27T05:54:03.597197+00:00 heroku[web.1]: State changed from starting to crashed
2019-08-27T05:54:03.569746+00:00 heroku[web.1]: Process exited with status 1
2019-08-27T05:59:55.107447+00:00 heroku[web.1]: State changed from crashed to starting
2019-08-27T05:59:58.079934+00:00 heroku[web.1]: Starting process with command `npm start`
2019-08-27T06:00:00.687008+00:00 heroku[web.1]: State changed from starting to crashed
2019-08-27T06:00:00.660988+00:00 heroku[web.1]: Process exited with status 1
2019-08-27T06:00:00.452248+00:00 app[web.1]: > [email protected] start /app
2019-08-27T06:00:00.452250+00:00 app[web.1]: > node index.js
2019-08-27T06:00:00.452252+00:00 app[web.1]:
2019-08-27T06:00:00.574510+00:00 app[web.1]: /app/index.js:1
2019-08-27T06:00:00.574514+00:00 app[web.1]: import express from "express";
2019-08-27T06:00:00.574517+00:00 app[web.1]: ^^^^^^^
2019-08-27T06:00:00.574519+00:00 app[web.1]:
2019-08-27T06:00:00.581327+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2019-08-27T06:00:00.581759+00:00 app[web.1]: npm ERR! errno 1
2019-08-27T06:00:00.582977+00:00 app[web.1]: npm ERR! [email protected] start: `node index.js`
2019-08-27T06:00:00.583139+00:00 app[web.1]: npm ERR! Exit status 1
2019-08-27T06:00:00.583436+00:00 app[web.1]: npm ERR!
2019-08-27T06:00:00.583640+00:00 app[web.1]: npm ERR! Failed at the [email protected] start script.
2019-08-27T06:00:00.583830+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2019-08-27T06:00:00.593702+00:00 app[web.1]:

My config: package.json file.

{
  "name": "realtime-chat",
  "version": "1.0.0",
  "description": "sjc-realtimechat",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "babel-node index.js",
    "postinstall": "bower cache clean && bower install"
  },
  "keywords": [
    "sjc"
  ],
  "author": "sjc-bui",
  "license": "ISC",
  "dependencies": {
    "babel-cli": "^6.26.0",
    "babel-preset-env": "^1.7.0",
    "bcrypt": "^3.0.6",
    "bluebird": "^3.5.5",
    "body-parser": "^1.19.0",
    "bower": "^1.8.8",
    "connect-mongo": "^3.0.0",
    "cookie-parser": "^1.4.4",
    "dotenv": "^8.0.0",
    "ejs": "^2.6.2",
    "emojione": "^4.5.0",
    "express": "^4.17.1",
    "express-flash": "0.0.2",
    "express-session": "^1.16.2",
    "express-validator": "^6.1.1",
    "fs-extra": "^7.0.1",
    "google-translate": "^2.2.0",
    "http": "0.0.0",
    "https": "^1.0.0",
    "lodash": "^4.17.11",
    "moment": "^2.24.0",
    "mongoose": "^5.6.4",
    "multer": "^1.4.1",
    "nodemailer": "^4.4.2",
    "passport": "^0.4.0",
    "passport-google-oauth": "^2.0.0",
    "passport-local": "^1.0.0",
    "passport.socketio": "^3.7.0",
    "request": "^2.88.0",
    "socket.io": "^2.2.0",
    "uuid": "^3.3.2"
  },
  "devDependencies": {}
}

My config: Procfile file

web: npm start

i'm trying to run babel-node index.js on server. but got this error

npm ERR! [email protected] start: node index.js

I was searching to fix it but still got this error. Please help.

Update

Dependences already installed but still got "npm start" error.

2

There are 2 best solutions below

3
On

Update all required dependencies in your package.json.

package.json should be something similar to this :

      {
          "name": "sample name",
          "version": "version details goes here",
          "description": "description goes here",
          "main": "index.js",
         "scripts": {
            "start": "babel-node index.js",
            "dev": "nodemon --exec babel-node index.js",
            "test": "mocha --require babel-core/register test/*.js",
            "compile": "babel src --out-dir .compiled --source-maps --watch",
            "postinstall": "bower cache clean && bower install"
          },

          "dependencies": {
            "express": "^4.9.8",
             "other dependencies"
          },
          "engines": {
            "node": "put node version details here"
          }

}

update your bablerc file as below:

babelrc content

{
  "presets": ["@babel/preset-env"]
}

Babel node is missing from your dependencies list.

also, see this below guide for more details:

https://devcenter.heroku.com/articles/deploying-nodejs

0
On

you cannot use

 import express from "express"

this is ES-15 modules and Node.js does not support this. React supports this. node.js runtime has support for common.js modules which should be like this:

 const express=require("express")