Zygimantas Berziunas Zygimantas Berziunas - 5 months ago 63
Node.js Question

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.

Answer

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.