AlvinfromDiaspar
AlvinfromDiaspar

Reputation: 6834

Azure node.js API App - Failing during run-time (possibly node.js version issue?)

I have a node.js API App that is being deployed via continuous delivery/deployment in VSO (Visual Studio Online).

I discovered that the app fails when i import modules such as 'express'. I installed 'express' on the azure machine, via Kudo console. But that didnt help.

The run-time error that i see in the output console:

Application has thrown an uncaught exception and is terminated:
SyntaxError: Unexpected token ILLEGAL
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (D:\home\node_modules\tedious\lib\tedious.js:4:29)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

Note that i did see this article which is suggesting to use node > 4. But as you can see in my package.json, i am explicitly referring to node > 6.

The package.json looks like this:

{
  "name": "my_API_Service",
  "engines": {
    "node": "6.11",
    "npm": "1.1.65"
  },
  "version": "1.0.0",
  "description": "",
  "main": "MyService.js",
  "dependencies": {
    "async": "^2.6.0",
    "body-parser": "^1.18.2",
    "express": "^4.16.2",
    "http": "0.0.0",
    "sequelize": "^4.28.6",
    "swaggerize-express": "^4.0.5",
    "swaggerize-ui": "^1.0.1",
    "tedious": "^2.1.5"
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-util": "^3.0.8"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "https://<my_api_service_url>"
  },
  "author": "",
  "license": "ISC"

============= Closed ===============

I finally got my app running (very intuitively might i add) by configuring it on Windows OS (instead of Linux OS). I was really set on having it run on Linux, but it turned out to be a walk thru a mine field. 

Upvotes: 3

Views: 1553

Answers (1)

starian chen-MSFT
starian chen-MSFT

Reputation: 33748

First, you can check whether node_modules is in wwwroot folder of web app service.

Secondly, based on this article: Using Node.js Modules with Azure applications

Azure Cloud Services expect all modules to be installed on the development environment, and the node_modules directory to be included as part of the deployment package. It is possible to enable support for installing modules using package.json or npm-shrinkwrap.json files on Cloud Services; however, this configuration requires customization of the default scripts used by Cloud Service projects. For an example of how to configure this environment, see Azure Startup task to run npm install to avoid deploying node modules.

So, it needs packages in node_modules (tested to compile nodejs app through webpack and deploy output files without node_modules to azure (Node JS Empty web app template), but failed to load. It works fine in local without node_modules (call node xx.js to start))

So, you can include the packages in deployment packages or refer to above article to use Windows Azure Startup task to run npm install to avoid deploying node modules.

Upvotes: 2

Related Questions