You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to get a web app that is compiled to nodejs ES6 syntax to work on a Windows based Azure app service but I am having absolutely no luck so im hoping someone here can help me. First up, my web config is the same as the MS quick start demo (comments removed for verbosity) for a nodejs application - as shown below:
In the root of my application I also have a very simple package.json file with a single property of type="module", as shown below, which simply tells node to use the newer syntax (I am doing this because the bundler that builds my app spits out .js files and not .mjs.):
{ "type": "module" }
With this configuration the app runs perfectly locally by simply running node index.js from any folder containing the app.
When I deploy the app to the azure app service however the page will not load. Checking the logs I can see the following error: require() of ES modules is not supported. require() of C:\home\site\wwwroot\index.js from C:\Program Files (x86)\iisnode\interceptor.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\home\site\wwwroot\package.json.
I found this suggestion on stackoverflow - which basically suggests adding a .cjs file to the root which simply imports the app. Then set this as IISNodes entry point in the web config. I have tried this solution, but the app doesnt work, it simply renders the index.js files as raw text in the browser.
Locally I am running node 14.17.0. In the application settings for the app service the node version is set to 14 and running node --version in the scm / kudu site returns 14.16.0 so the node version is fine. What can I do to get this working??
The text was updated successfully, but these errors were encountered:
Hi there,
I am trying to get a web app that is compiled to nodejs ES6 syntax to work on a Windows based Azure app service but I am having absolutely no luck so im hoping someone here can help me. First up, my web config is the same as the MS quick start demo (comments removed for verbosity) for a nodejs application - as shown below:
In the root of my application I also have a very simple package.json file with a single property of type="module", as shown below, which simply tells node to use the newer syntax (I am doing this because the bundler that builds my app spits out .js files and not .mjs.):
{ "type": "module" }
With this configuration the app runs perfectly locally by simply running node index.js from any folder containing the app.
When I deploy the app to the azure app service however the page will not load. Checking the logs I can see the following error:
require() of ES modules is not supported. require() of C:\home\site\wwwroot\index.js from C:\Program Files (x86)\iisnode\interceptor.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules. Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\home\site\wwwroot\package.json.
I found this suggestion on stackoverflow - which basically suggests adding a .cjs file to the root which simply imports the app. Then set this as IISNodes entry point in the web config. I have tried this solution, but the app doesnt work, it simply renders the index.js files as raw text in the browser.
Locally I am running node 14.17.0. In the application settings for the app service the node version is set to 14 and running node --version in the scm / kudu site returns 14.16.0 so the node version is fine. What can I do to get this working??
The text was updated successfully, but these errors were encountered: