Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom start-up command for Azure Node.js Web app (ES2015/babel)?

I am migrating an ES2015 node.js application from Heroku to Azure.

The current start-up command running on Heroku is

"start": "./node_modules/babel-cli/bin/babel-node.js index.js"

However, on Azure I am getting

Invalid start-up command "./node_modules/babel-cli/bin/babel-node.js index.js" in package.json. Please use the format "node <script relative path>".

Which indicates that Azure only supports vanilla node for npm start.

I'm aware that running babel-node on production isn't ideal, but I was hoping for a straightforward migration.

Three options that would require a bit of re-architecting are:

  1. Using a gulp workflow to precompile ES2015: https://github.com/christopheranderson/azure-node-es2015-example
  2. Using a bash workflow to precompile ES2015: http://www.wintellect.com/devcenter/dbaskin/deploying-an-es6-jspm-nodejs-application-to-azure
  3. Using babel-register ala [link in comments].

I suspect option 3 will be easiest but checking if anyone has come across a similar issue and managed to run babel-node directly in npm start on Azure.

like image 825
Amadeus Stevenson Avatar asked Apr 18 '16 21:04

Amadeus Stevenson


2 Answers

According your issue, please modify your start npm script to node ./node_modules/babel-cli/bin/babel-node.js index.js on Azure Web Apps.

Here is the content in test package.json:

{
  "name": "website",
  "description": "A basic website",
  "version": "1.0.0",
  "engines": {
    "node": "5.9.1",
    "npm": "3.7.3"
  },
  "scripts": {
    "start": "node ./node_modules/babel-cli/bin/babel-node.js index.js"
  },
  "dependencies": {
    "babel-preset-es2015": "^6.6.0",
    "babel-cli": "^6.0.0"
  }
}

Meanwhile if you need a higher Node.js version, you can specify in package.json, refer to https://azure.microsoft.com/en-us/documentation/articles/nodejs-specify-node-version-azure-apps/ for more.

like image 80
Gary Liu Avatar answered Nov 12 '22 06:11

Gary Liu


Just as what Gary said, you need to update your package.json using the command below.

"scripts": {
    "start": "node ./node_modules/babel-cli/bin/babel-node.js index.js"
  }
like image 27
Alex Chen-WX Avatar answered Nov 12 '22 06:11

Alex Chen-WX