11

I'm running a nodejs app on azure web apps and i'm trying to integrate babel using npm in it. The problem is that babel is trying to acccess a file at

%USERPROFILE%

named .babel.json, a file that doesn't exist. This is most likely installed by:

npm install -g babel

On azure web apps, i can't seem to find it at all (even after running npm install -g babel in kudu for the site).

I copied the file in %USERPROFILE% myself to %USERPROFILE% using kudu but on web app restart the file disappears.

Is there a way to make babel work on web apps?

UPDATE

I did omit some things. The error appeared when i tried load babel/register.

require('babel/register')({
  optional: ["es7.asyncFunctions"]
});

and the actual error i see in the streaming logs is

Application has thrown an uncaught exception and is terminated: Error: ENOENT, no such file or directory 'D:\local\UserProfile.babel.json' at Object.fs.openSync (fs.js:438:18) at Object.fs.writeFileSync (fs.js:977:15) at save (D:\home\site\wwwroot\node_modules\babel\node_modules\babel-core\lib\api\register\cache.js:35:19) at process._tickCallback (node.js:419:13) at Function.Module.runMain (module.js:499:11) at startup (node.js:119:16) at node.js:906:3

the project is on Github

Leonid Beschastny
  • 50,364
  • 10
  • 118
  • 122
Alex
  • 10,869
  • 28
  • 93
  • 165
  • Try to run the command `npm install --save-dev babel-core`. The option `-g` for npm will install the package into the global path for node modules. In Azure, the path is protected. – Peter Pan Sep 24 '15 at 09:59
  • @Badescu,Due to this issue is hard to reproduce on my environment, Could you please share your web site information with us via leveraging the approach that pointed out at https://github.com/projectkudu/kudu/wiki/Reporting-your-site-name-without-posting-it-publicly ? – Will Shao - MSFT Oct 13 '15 at 01:50

4 Answers4

20

I had this same problem, solved it by disabling the babel cache by setting the environment variable BABEL_DISABLE_CACHE=1 in my Application settings.

You can read more about the babel cache here: https://babeljs.io/docs/usage/require/#environment-variables

user1113977
  • 216
  • 2
  • 2
4

You change the store location of .babel.json by BABEL_CACHE_PATH

I think its better than disable caching

BABEL_CACHE_PATH=any_writable_and_exist_dir/babel.cache.json

S. Ali Mihandoost
  • 2,873
  • 3
  • 18
  • 24
3

The error appeared when i tried load babel/register.

Please check the Cache.js at (..\node_modules\babel\node_modules\babel-core\lib\api\register\Cache.js) to see if there is any babel cache path definition, e.g.

process.env.BABEL_CACHE_PATH || _path2["default"].join(_homeOrTmp2["default"], ".babel.json");

If you leverage this kind of variables, it's needed to have BABEL_CACHE_PATH app setting key and value of ./cache otherwise anything with babel wouldn't work on azure. Please refer to http://blog.syntaxc4.net/post/2012/07/26/accessing-app-settings-configured-in-microsoft-azure-web-sites-using-php-and-node-js.aspx in case you wanna know the details of accessing app settings in Azure web site using node.js.

Should you have any further concern, please feel free to let us know.

Ming Xu - MSFT
  • 2,116
  • 1
  • 11
  • 13
0

I create a nodejs app from Azure Gallery "Node JS Empty Web app" and run the command npm install -g babel in Kudu. I tried to reproduct your issue, but failed that the babel is not trying to access the file .babel.json at %USERPROFILE%.

On Azure, the npm global modules will be installed into the path "D:\local\AppData". When you restart the WebApp, the node global modules will be deleted.

If you have to use the node global modules, you can configure a startup task for a node web role to install node modules when web role start up in Cloud Service. Please refer to https://azure.microsoft.com/en-us/documentation/articles/cloud-services-startup-tasks/.

Normally, installed node modules by using npm install <module-name> at the path "wwwroot" of Kudu Debug Console on Azure Web Apps.

I tried to install the babel module at the path "wwwroot" and run the command node_module\.bin\babel, and write a file include the code require('babel') to run it successfully. It works fine.

Best Regards.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • Thanks for the reply Peter. I did omit some things. i've **UPDATE**-ed my question. The issue may very well not be from the global modules, it was an assumption i made. I've created a test project and did reproduce it again using Git deploy. I've uploaded it to https://github.com/badescuga/testbabelrequire – Alex Sep 25 '15 at 14:56
  • @BadescuAlexandru I installed babel module by using the command `npm install babel` (not `babel-core`) in the path `wwwroot` within Kudu. I tried to reproduce your issue when node run js script file with loading `babel/register` at the same path `wwwroot`, but no expection happended. Your issue maybe caused by your installed module is `babel-core`. Can you check the node_modules directory? – Peter Pan Sep 28 '15 at 04:48
  • i've checked and i got `babel`. It's weird you're not getting any issues. Are you sure you're executing server.js? Do you see any .babel.json in D:\local\UserProfile? Note that for deploying, i've used git (so kudu did the compiling for me) – Alex Sep 28 '15 at 11:14