Zygimantas
Zygimantas

Reputation: 8787

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:

  1. Clone the https://github.com/intellismiths/webapp1 repository.
  2. Create new Azure Web App (default settings).
  3. Configure deployment source to use GitHub.
  4. Click Sync. It will take 10+ minutes to complete and it will show that the deployment was successful.
  5. Go to Application settings in Azure and change WEBSITE_NODE_DEFAULT_VERSION to 6.2.2
  6. Go to kudu page and open powershell console.
  7. Execute npm cache clean
  8. Check node version by executing node -v. It should be v6.2.2
  9. On Azure, navigate to D:\home\site\respository\src\WebApp1
  10. Execute npm run build
  11. In console, you should see a lot of errors which indicates that modules can not be resolved.
  12. OPTIONAL. Test npm run build on your local machine - it should produce wwwroot/app.js without errors.
  13. Update webpack.config.js to include context: __dirname to fix previous errors.
  14. Execute npm run build
  15. 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.

Upvotes: 3

Views: 2354

Answers (5)

aumanjoa
aumanjoa

Reputation: 955

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

Upvotes: 1

Martín Coll
Martín Coll

Reputation: 3804

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

Upvotes: 3

Anders Fjeldstad
Anders Fjeldstad

Reputation: 10824

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.

Upvotes: 1

Gary Liu
Gary Liu

Reputation: 13918

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.

Upvotes: 4

Iceman
Iceman

Reputation: 6145

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

Upvotes: 0

Related Questions