Azure's node Deploy uses wrong Node and NPM - node.js

When I deploy to Azure WebSite the node runtime correctly uses the Nodejs I config in package.json, however the deployment script uses the node and NPM on the server's path. (The Server path is messed up and has both node version in the path.)
Ex. I want nodejs 4.2.1 and NPM >2
When I deploy an app it uses 0.10.x and NPM 1.x.x. My rxjs module requires NPM > 2 so it fails to load.
If I deploy avoiding the packages I can see the correct runtime is run.
Is there a way to fix this issue?

You can simply customize the nodejs version in Azure manage portal.
In CONFIGUE tab of your web site portal, under the APP SETTINGS section, the nodejs version is set as WEBSITE_NODE_DEFAULT_VERSION to 0.10.32 by Azure default, we can directly change it value to 4.2.1 you want.
Click the restart button at bottom nav bar after you modified the site setting.
Login on your KUDU console site, you can check the nodejs version in the cmdlet.(The site URL should be: https://{your site name}.scm.azurewebsites.net/DebugConsole)
And the nodejs version is 4.2.1 with npm version 3.3.9 after modification.
You can get more info at Specifying a Node.js version in an Azure application.

There are also atleast two other mentions on various sources claiming that it can be set via package.js:
"engines": {
"node": ">= 8.2.0 || 8.x.x",
"npm": ">= 5.3.0 || 5.x.x"
},
Or via the iisnode.yaml file in the site directory root. Which one does the trick is really hard to discover since you can only tell the node version correctly during runtime of the app.

Related

How to change nodejs CLI version on Cpanel/Whm

On setup nodejs app in the cpanel menu, there are so many version choice.
But when I login using ssh, the shown version is v8.17.0. How to change to 12 or later?
First you need to create nodejs application on your cpanel then the NPM binary executable will be created on /home/yourcpanelusername/nodevenv/yourprojectname/12/bin/. So just use it, example:
~/nodevenv/yourprojectname/12/bin/npm install
or if using node:
~/nodevenv/yourprojectname/12/bin/node index.js

why I am using different node runtime version in cloud function?

as you can see at the image above, locally I am using node v10.16.3, but from cloud function dashboard it seems I still using runtime node JS 8. is this ok ? or do make something wrong ?
According tho the documentation: "You have to set the version in the engines field in the package.json file that was created in your functions/ directory during initialization" link.
Please keep in mind that Node.js 10 runtime is currently in beta.
For example, to use only version 10, edit this line in package.json:
"engines": {"node": "10"}

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

How do I use the older version of node.js buildpack?

I've been using Node.js as my runtime within Bluemix for a few weeks now but I saw somewhere that there's a new version of the runtime now live on Bluemix. I have some changes to my app that need to be pushed but I'm not sure if I'm quite ready to move to the new buildpack version yet. Is there a way to use the older version of the buildpack while I complete my testing?
Yes, you can still use v1.18, as it will be available on Bluemix for a period of time and can be accessed using the CF command below:
$ cf push your_app_name -b sdk-for-nodejs_v1-18-20150519-1759
Or, you can specify the following in your manifest.yml:
buildpack: sdk-for-nodejs_v1-18-20150519-1759
All available buildpacks installed on the system can be viewed using the following command:
$ cf buildpacks
If you're concerned about the default version of Node.js moving from 0.10 to 0.12 with the buildpack updates, it is still possible to manually specify the runtime version by setting the following property in your package.json file:
"engines": {
"node": "0.10.x"
}

Resources