Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

babel-node not recognized while running heroku local web

I tried deploying Node.js API on Heroku, but shows Application Error.

So, used the "heroku local web" command to test any error..and got an error saying that 'babel-node' is not recognized as an internal or external command, operable program or batch file.

On the other hand, when I run the command 'npm start' I dont get any error and the server starts running.

package.json

 {
      "name": "apollo-starter-kit",
      "version": "0.1.0",
      "description": "Minimal set of code to write a GraphQL server with Apollo graphql-tools",
      "scripts": {
        "start": "nodemon ./server.js --exec babel-node",
        "test": "echo \"Error: no test specified\" && exit 1",
        "lint": "eslint ."
      },
      "repository": {
        "type": "git",
        "url": "git+https://github.com/apollostack/apollo-starter-kit.git"
      },
      "keywords": [
        "Node.js",
        "Javascript",
        "GraphQL",
        "Express",
        "Apollo",
        "Meteor"
      ],
      "author": "Jonas Helfer <[email protected]>",
      "license": "MIT",
      "bugs": {
        "url": "https://github.com/apollostack/apollo-starter-kit/issues"
      },
      "homepage": "https://github.com/apollostack/apollo-starter-kit#readme",
      "dependencies": {
        "apollo-server": "^0.1.2",
        "casual": "^1.5.10",
        "cors": "^2.8.1",
        "express": "^4.13.4",
        "lodash": "^4.17.4",
        "mongoose": "^4.8.1",
        "sequelize": "^3.30.2",
        "sqlite": "^2.3.0"
      },
      "devDependencies": {
        "babel-cli": "6.5.1",
        "babel-core": "^6.5.2",
        "babel-eslint": "^6.0.0-beta.6",
        "babel-loader": "6.2.3",
        "babel-plugin-inline-import": "^2.0.1",
        "babel-polyfill": "6.5.0",
        "babel-preset-es2015": "6.5.0",
        "babel-preset-react": "^6.5.0",
        "babel-preset-stage-0": "6.5.0",
        "casual": "^1.5.10",
        "eslint": "^2.4.0",
        "eslint-config-airbnb": "^6.1.0",
        "eslint-plugin-import": "^1.1.0",
        "eslint-plugin-react": "^4.2.3",
        "graphql": "^0.6.0",
        "nodemon": "^1.9.1"
      },
      "peerDependencies": {
        "graphql": "^0.5.0 || ^0.6.0"
      },
      "eslintConfig": {
        "parser": "babel-eslint",
        "extends": [
          "airbnb/base",
          "plugin:import/errors"
        ],
        "rules": {
          "no-use-before-define": 0,
          "arrow-body-style": 0,
          "dot-notation": 0,
          "no-console": 0
        },
        "env": {
          "mocha": true
        }
      }
    }
like image 490
ANKIT HALDAR Avatar asked Mar 07 '17 14:03

ANKIT HALDAR


2 Answers

I think the most likely cause is that babel is part of dev dependencies and those are not installed by default via official node.js buildpack. Change NPM_CONFIG_PRODUCTION to false and it should work.

You can use command line

heroku config:set NPM_CONFIG_PRODUCTION=false

You can always login into Heroku dyno to check if everything is installed properly

heroku run bash
like image 75
Michał Młoźniak Avatar answered Sep 22 '22 21:09

Michał Młoźniak


You should not be using babel-node in production. It is unnecessarily heavy, with high memory usage due to the cache being stored in memory. You will also always experience a startup performance penalty as the entire app needs to be compiled on the fly.

ref: https://medium.com/@Cuadraman/how-to-use-babel-for-production-5b95e7323c2f

like image 34
Nay Avatar answered Sep 20 '22 21:09

Nay