How to use latest version of nodejs on azure mobile-service runtime - azure

I am trying to integrate google-api-nodejs-client with azure mobile-services. I get following runtime error trying to use sample code from googleapis:
Error: Unable to load endpoint plus("v1"): Cannot read property 'prototype' of undefined
This error seems to be due to reason that googleapis only support nodejs version 0.10 and higher, whereas azure mobile-services are running nodejs version 0.8.28.
Is there a way I can use more latest version of nodejs on azure mobile-service?

A workaround suggested by David Ebbo on Azure Support Site
You may want to try something like this as a workaround:
at the root of the repo, you'll find a .deployment file that has:
[config]
command = ..\ZumoDeploy.cmd
Change it to
[config]
command = deploy.cmd
And create a deploy.cmd next to it containing:
set NPM_JS_PATH=%ProgramFiles(x86)%\npm\1.4.9\node_modules\npm\bin\npm-cli.js
..\ZumoDeploy.cmd
Commit both files and push.

Related

An unknown error has occurred. Check the diagnostic log for details

New to Azure : I am using azure free service to host react website using vs code extension Azure App Service.
While deploying I am getting following error with no specific details
Using Node version:
v14.18.3
Using Npm version:
6.14.15
Running 'npm install --unsafe-perm'...
> react-scripts build
Creating an optimized production build...
An unknown error has occurred. Check the diagnostic log for details.
Deployment failed.
Inside Azure All Service :- microsoft.alertsmanagement/smartdetectoralertrules
Failure Anomalies notifies you of an unusual rise in the rate of failed HTTP requests or dependency calls.
Steps to reproduce
First deployment worked for me
After adding new dependancy in package.json it is not working (previously worked adding same dependancy)
Adding new png assets to project is failed, every time reason is different of failing
Trials to solve
Deleted projects and re created
Updated project dependancy
New project created but its fails after some changes to project
Please help to solve this problem

How to add ICU data to Node.js in AWS Lambda?

My question is similar to an existing one, but I'm using webpack and thus don't even have a "node_modules" directory.
I've still tried the following environment variable settings without success:
NODE_ICU_DATA: 'node_modules/full-icu'
NODE_ICU_DATA: '/var/task/node_modules/full-icu/icudt58l.dat'
NODE_ICU_DATA: '/var/task/node_modules/full-icu/icudt60l.dat'
All without success, the lambdas simply refuse to start and a log message is show in CloudWatch:
/var/lang/bin/node: could not initialize ICU (check NODE_ICU_DATA or --icu-data-dir parameters)
I found very little about this problem on Google, which seems curious given that it should concern so many that are building internal apps on AWS lambda.
Make sure you're deploying the correct .dat file version into the directory defined by NODE_ICU_DATA. In my case, the correct file was icudt62l.dat when using the runtime nodejs10.x for my lambdas. If you're not deploying node_modules as part of your lambda, you can grab the correct .dat file and deploy that.
I ran into the same error message when upgrading the runtime version of some old lambdas from nodejs6.10 to nodejs10.x. In my case, the file icudt58l.dat (compatible with nodejs6.10) was deployed into the project root, and the value of NODE_ICU_DATA was . (i.e. the directory where my lambda executes, equivalent to /var/task/).
To get a compatible .dat file, I re-installed the full-icu package using the node version used by the lambdas:
npx -p node#10.x npm i full-icu
It's important that the version of the .dat file is correct for the runtime version your lambdas are using. Initially, I made the mistake of just running npm i full-icu using node version 10.0 but this installed the wrong version of the .dat file and I just got the same error message again.
Finally, I copied the file node_modules/full-icu/icudt62l.dat into the project root and deleted the old icudt58l.dat so that it ends up in /var/task/ where the lambda can find it when NODE_ICU_DATA=..

Express app with Node-sass on Azure App Service

I have a basic node web application using express that has a dependency on the node-sass library.
This is being built on a Win64 server, so during the npm install part of the build it is downloading the x64 version of the binding binary due to the current environment.
When its deployed to Azure App Service it throws a runtime error due to incompatability with the node-sass binding binary, as node runs 32bit in Azure App Service...
Error: Missing binding
D:\home\site\wwwroot\node_modules\node-sass\vendor\win32-ia32-48\binding.node
Node Sass could not find a binding for your current environment:
Windows 32-bit with Node.js 6.x
Found bindings for the following environments:
- Windows 64-bit with Node.js 6.x
When i explicitly check in the 32bit binding and re-deploy i sometimes get a 502 gateway error...
502 - Web server received an invalid response while acting as a
gateway or proxy server. There is a problem with the page you are
looking for, and it cannot be displayed. When the Web server (while
acting as a gateway or proxy) contacted the upstream content server,
it received an invalid response from the content server.
and other times i simply get a 500, but it no longer writes the error to the log.
The app depends on node-sass-middleware package version 0.11 explicitly, which depends on node-sass 4.3.0.
Without any error logs i am at a dead end. Have you come across this issue before, and if so, how did you resolve it?
I leveraged Node-Sass Example App to have quick test, used local git to deploy it sample project to Azure Web Apps, which reproduced your issue.
Via the deployment log:
remote: Selected node.js version 7.4.0. Use package.json file to choose a different version.
remote: Selected npm version 4.0.5
And according the similar error message:
Found bindings for the following environments: - Windows 64-bit with Node.js 6.x
I specified the node.js version in package.json to:
"engines": {
"node": "= 6.9.1",
"npm": "> 3"
}
Then redeploy it to Azure via local git, and the sample works fine.
For your further 500 error, you can try to leverage App Service Editor to check the output of your website.
Enter the App Service Editor from Azure portal, switch to output section by clicking the show output button, then click run to start the application.
We eventually resolved this by swapping out node-sass-middleware for gulp-sass, and also adding an npm rebuild step for node-sass. The key difference here is that the css is now rendered during the build process via gulp. Running npm rebuild node-sass first would invoke the binding download to the build server (if necessary), and then a separate task would invoke a gulp task to render the css.
The remainder of our problem was due to the fact that the web.config specified app.js as the entry point, but express4 uses the bin/www file, and simply references app.js. The problem with bin/www being the entry point is that iisnode now uses bin as the working directory, which caused issues with root relative references.
Rather than waste any more time trying to figure out if we could configure a different working directory, we simply moved bin/www to ./server.js and changed the web.config to point to server.js
The express app now runs as expected on azure websites.

Azure and node js __dirname

Probably it is not specifically related to webpack/memory-fs, but I am getting the RangeError: Maximum call stack size exceeded error (see below for a call stack).
I have found out, that __dirname on Azure (webapp) returns \\100.78.172.13\volume-7-default\8f5ecde749dace2bb57a\4e07195f015b45ce8e9ba255dc901988\site\repository\Source\Website\Content\app\node_modules\webpack\node_modules\memory-fs\lib\normalize.js in my situation, while process.cwd() returns D:\home\site\repository\Source\Website\Content\app.
Is anything can be done from my side to configure node js to return D:\... instead of \\.. ?
Gist
How to reproduce:
Clone the https://github.com/intellismiths/webapp1 repository.
Create new Azure Web App (default settings).
Configure deployment source to use GitHub.
Click Sync. It will take 10+ minutes to complete and it will show that the deployment was successful.
Go to Application settings in Azure and change WEBSITE_NODE_DEFAULT_VERSION to 6.2.2
Go to kudu page and open powershell console.
Execute npm cache clean
Check node version by executing node -v. It should be v6.2.2
On Azure, navigate to D:\home\site\respository\src\WebApp1
Execute npm run build
In console, you should see a lot of errors which indicates that modules can not be resolved.
OPTIONAL. Test npm run build on your local machine - it should produce wwwroot/app.js without errors.
Update webpack.config.js to include context: __dirname to fix previous errors.
Execute npm run build
In console, you should see the "RangeError: Maximum call stack size exceeded" error.
Update 1
I only tried to set 6.2.2 runtime after adding the second package.json, so the project structure is not the simplest possible. Maybe just setting node to 6.2.2 breaks the build.
I could reproduce your issue following your steps. I found the key point was setting the WEBSITE_NODE_DEFAULT_VERSION to 6.2.2. And I found the webpack task worked fine if the WEBSITE_NODE_DEFAULT_VERSION was under 6.
Please downgrade the setting WEBSITE_NODE_DEFAULT_VERSION to the version under 6 e.g. 5.9.0 if your node.js modules do not need such high version.
And according the package.json of angular2 athttps://github.com/angular/angular/blob/master/package.json, it seems that the angular2 repository requires the node.js version between 5.4 and 6.
Additionally, the web application's root directory on Azure Web Apps is D:\home\site\wwwroot. So if you want to build your frontend project on Azure Web Apps, you need to locate to D:\home\site\wwwroot\wwwroot\mobile-web-app then run npm run build.
It's been fixed in master and it's proposed to be included in v6.4.0.
See: https://github.com/nodejs/node/issues/7175#issuecomment-239824532 and https://github.com/nodejs/node/pull/8070
After a long day of research, trial-and-error and various experimentation, I've found an acceptable workaround if you're not willing to downgrade to Node 5.*:
Downgrade to Node 6.1.0
Make sure to install webpack globally (with npm install -g webpack).
Just using 6.1.0 gets around the "maximum call stack size exceeded" error, but instead gave me a lot of resolve failures when running webpack from node_modules (using ./node_modules/.bin/webpack). Installing webpack globally finally got me past that.
If I understand it correctly, this whole issue with __dirname in Node >= 6.2 resolving to the UNC folder path instead of the mounted path is going to be fixed, there's an active discussion here.
I had the same issue.
Fixed it with UPGRADING npm not DOWNGRADING.
Bug is fixed in the npm versions newer than 6.5.
https://github.com/aumanjoa/chronas-community/blob/master/package.json#L48
I believe that your __dirname shows your persistant drive where the data is stored, while .cwd gives current directory from where node ran. This is because Azure runs from the Drive but files are stored at the persistent drive.
In your Gruntfile.js add
module.exports = function (grunt) {
grunt.file.setBase(__dirname);
// Code omitted
}
Refer: link

Cannot deploy node.js app on GAE

I'm having trouble deploying my node.js app to GAE.
It's a simple app that connects to my Firebase and updates a value. Just to get started.
Whenever I try to deploy the app it fails. Runs fine locally.
I deleted my project and started a fresh one, and deployed the default 'hello-world' app after downloading the zip and it worked fine.
I installed firebase on the project via the cloud shell.
Added
var Firebase = require("firebase");
to the app.js file and it no longer deploys.
I am new to GAE and cannot understand why it won't deploy. I feel like if i'm having trouble just including firebase in an app, I'm in for a tough time.
This is the error I get. The only think I have added to the original hello-world app is the firebase dependency. I remove that and it deploys fine again.
Updating service [default]...failed.
ERROR: (gcloud.preview.app.deploy) Error Response: [13] Timed out when starting VMs. It's possible that the application code is unhealthy. (0/2 ready, 2 still deploying).
Any help would be greatly appreciated.
I fixed the issue by installing the firebase npm on my local machine again. I noticed when I was installing it on the server (even with --save) it wasn't updating the package.json file for some reason and it hadn't updated it locally either. But it still ran on my local machine without the package mentioning a firebase dependency. Not sure why that would be the case.
It seems to be working now.
Before you can require the "firebase" package you need to install it.
To install the latest version of the package using the command line:
Navigate to the project root directory
Run npm install --save firebase
You will now have Firebase, and all the packages that it depends on, installed in your app.
The --save argument makes the command save the package installation configuration to the package.json file, so that the package is installed when you run the npm install command to set up the project on another computer, or when your app is deployed to Google App Engine.
You can check the logs for error. To check it goto your project at google console (console.cloud.google.com) and then Menu-> Logs.
Usually this error comes when app couldn't start while deploying. 1st check if the app local environment. If it is working fine then check if any environment variable is required to set and not set properly on cloud.

Resources