3

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. 
AlvinfromDiaspar
  • 6,611
  • 13
  • 75
  • 140
  • What's in your package.json file? Also, make sure CD uses "npm run" to launch, so it will install all of the module. – Jim B. Jan 01 '18 at 02:19
  • in my build definition the first step is "npm install". Do you mean this should this be "npm run" instead? Or do you mean "npm install -g npm-run" ? – AlvinfromDiaspar Jan 02 '18 at 19:16

1 Answers1

2

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.

starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53
  • Would another option be to use gulp to copy/deploy the node_modules to the deploy location? – AlvinfromDiaspar Jan 02 '18 at 17:35
  • I have now configured a task to copy everything to the wwwroot location. I can now see the node_modules folder there. However, i still see this same stacktrace error. – AlvinfromDiaspar Jan 02 '18 at 18:50
  • Can you share build and release log on the OneDrive (remove personal information)? – starian chen-MSFT Jan 03 '18 at 01:24
  • Click Download all logs as zip in a build or release result page. How do you create app service in azure? What are files in app service? (check files through Kudu: `http://xxx.scm.azurewebsites.net/`) – starian chen-MSFT Jan 03 '18 at 01:30
  • Access `https://[appname].scm.azurewebsites.net/DebugConsole` and click site>wwwroot. – starian chen-MSFT Jan 03 '18 at 01:41
  • Yes, that kudu url has been very helpful for my debugging. The wwwroot seems to have everything the site needs. But unfortunately i am seeing the exception mentioned in the post. – AlvinfromDiaspar Jan 03 '18 at 03:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/162386/discussion-between-alvinfromdiaspar-and-starian-chen-msft). – AlvinfromDiaspar Jan 03 '18 at 03:25