How can I get my azure function app to support EcmaScript Modules?

Jeremy 20 Reputation points
2023-07-19T15:27:35.8366667+00:00

According to this https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-node?tabs=javascript%2Clinux%2Cazure-cli&pivots=nodejs-model-v4#ecmascript-modules

Azure functions allegedly support Ecmascript modules.

However, when I convert my functions to .mjs I am met with the following error message:

Worker was unable to load entry point "src/functions/*.js": missing ) after argument list

How do I change the entry point to look for .mjs files?

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,399 questions
{count} votes

Accepted answer
  1. Pramod Valavala 20,656 Reputation points Microsoft Employee
    2023-07-20T16:14:46.17+00:00

    @Jeremy The v4 Programming Model requires you to set the entry point by setting the main property in your package.json file.

    When working with es modules, since your files are renamed to *.mjs you need to update the value for main in package.json to it as well.

    The default value for main in package.json for JavaScript functions is src/functions/*.js which needs to be changes to src/functions/*.mjs to get it to work with es modules.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.