Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto-Detect "index.cjs" files as primary for node functions #8213

Closed
hossam-nasr opened this issue Mar 8, 2022 · 1 comment
Closed

Auto-Detect "index.cjs" files as primary for node functions #8213

hossam-nasr opened this issue Mar 8, 2022 · 1 comment
Assignees

Comments

@hossam-nasr
Copy link
Contributor

What problem would the feature you're requesting solve? Please describe.

This issue is implemented in #8205

In the JavaScript world, there are two ways to import/export modules: CommonJS (default for node) and ES Modules (default for JavaScript).

The default for Azure Functions is to support exported functions in the CommonJS format, as follows:

module.exports = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');
    context.res = { 
        status: 200
    };
};

We also now support ES Modules in preview, as follows:

export const httpTrigger = async function (context, req) {
    context.log('JavaScript HTTP trigger function processed a request.');
    context.res = {
        status: 200
    };
};

Currently, the only way we support ESM is if the file ends with the .mjs extension. However, we also want to respect the type property of package.json files, as described in this issue in the node worker. To fully support this, we need to support .cjs extension files as well, as described here.

This issue on the host side is to automatically detect index.cjs files as the scriptFile for node functions, in addition to the existing index.js and index.mjs.

Describe the solution you'd like

The Host automatically detects index.cjs files as the scriptFile for node functions, if index.js and index.mjs are not present. Implementation in #8205

@hossam-nasr
Copy link
Contributor Author

Closing this issue, addressed here: #8205

@ghost ghost locked as resolved and limited conversation to collaborators Apr 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants