-
Notifications
You must be signed in to change notification settings - Fork 45
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
Respect package.json type: module for ESM Functions #531
Comments
If you're happy for me to PR this in, would you prefer the v3 or v4 branch? |
v3 branch. That being said, you will need the function app directory from the host in order to read the package.json and I don't think that's currently available. AFAIK, it was first added with the new worker indexing changes, but I would prefer if you let us integrate those changes. You're welcome to investigate a different method for reliably getting the package.json contents (let me know if you find one), but I will likely start that integration work soon anyways. |
My thought was to have the Given that Agreed that the new worker indexing will probably make things simpler, and I wouldn't want to rush that integration, but I'm just exploring how to make it easier to do ESM with TypeScript (in particular), as I keep getting caught on that (so it's totally a self-serving objective here 🤣). |
We should be conscience that this may surprise some users if suddenly their package.json "type" field is respected, especially since our es6 support is technically in preview. I don't anticipate many people would have their type set to "module" (I don't think it's the default anywhere?) so probably not a big deal. I think it would be nice if we added support for .cjs files at the same time as we respect "type" per the docs:
|
Agreed, I'd see the decision tree being:
|
The preview support for ESM (ES6) modules available (#104 for tracking) requires the use of
mjs
file extensions (https://github.com/Azure/azure-functions-nodejs-worker/blob/v3.x/src/FunctionLoader.ts#L31 for source reference) which is a bit of a pain when it comes to working with TypeScript, you need to use the nightly compiler to output amjs
extension.It would be good if the worker would respect the
type
field in package.json and if that is set tomodule
it loads them as ESM rather than commonjs.The text was updated successfully, but these errors were encountered: