简体   繁体   中英

Deploying Node/Express App to Heroku/Production — Babel/ES6 Error

I'm having a lot of trouble deploying to heroku/production with babel(using babel-cli) + es6 javascript . My app is a simple express and node server written in es6 style javascript.

I'm using " babel-cli " (installed via package.json) and a postinstall script inside package.json to precompile my es6 javascript into a " build " folder before starting the server.

The weird thing is that everything compiles smoothly with babel-cli for development, but not for production.

When deploying to production/heroku, the build process gets stuck on the babel command in Makefile and throws an error.

Package.json

{
  "name": "messenger-basic",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "clean": "rm -rf build && mkdir build",
    "build-server": "babel src --out-dir build",
    "build": "npm run clean && npm run build-server",
    "postinstall": "make build",
    "start": "node ./build/server.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel-preset-es2015": "^6.9.0",
    "body-parser": "^1.15.2",
    "express": "^4.14.0",
    "request": "^2.72.0"
  },
  "engines": {
    "node": "4.4.5"
  },
  "devDependencies": {
    "babel-cli": "^6.10.1",
    "babel-preset-stage-2": "^6.11.0"
  }
}

Makefile :

build: clean server_build

clean:
    rm -rf build
    mkdir -p build

server_build:
    babel src --out-dir build
    rsync -av --include \*/ --include \*.json --exclude \*  ./src/ ./build/
    rsync -av --include \*/ --include \*.ejs --exclude \*  ./src/ ./build/

.PHONY: build clean

The error :

You have mistakenly installed the `babel` package, which is a no-op in Babel 6.

Babel's CLI commands have been moved from the `babel` package to the `babel-cli` package.

Any help would be much appreciated! Setting up server stuff is my worst nemesis! :(

I usually run babel through weback, so I could be wrong here (I don't typically use makefiles), BUT, I would assume you would need to install babel-core in order for it to run correctly? It seems like the error is related to the fact that you just have "babel" installed, which will not work with v6. You need to install its components, which at minimum would require "babel-core."

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