-
Notifications
You must be signed in to change notification settings - Fork 136
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
Support for node ES6 modules #210
Comments
I would suggest not using loadModules then. I also don’t personally use ES modules natively on the server, I see no reason to yet. |
Should I take that as a "No, this will not be supported"? Not using When maintaining a library used by thousands of teams around the world then, no offence, but what you personally use or don't use is of little relevance. ES6 modules will be used more frequently going forward and I won't be the last person to encounter this. Again, I'm happy to help out and submit a PR if you have any ideas on what needs to be changed in order for |
Having to make loadModules async and use dynamic import is a breaking change. Whats the lowest version of Node that supports this ootb? I don’t want to cut off older versions just yet. Does it work even when the loaded module is CJS? There is nothing stopping you from writing a load modules impl that uses listModules and dynamic import externally. |
What I personally do and don’t do is relevant because often times people are doing things with Awilix that they shouldn’t. That might not be the case here but me stating that I don’t use ES modules on the server because I don’t see any additional value yet isn’t hurting anybody. |
Yeah, that's the drawback, another option would be to add it as an option or create a separate function. None of the solutions are great but I think enforcing the async behavior is not a good idea, especially since I imagine a lot of calls to Node 14 is the first to support this natively, so it's still fairly new. However simply because Line 99 in 10ab656
Doing
That's fair, I interpreted your original comment as "I'm not using this so it's not relevant". My bad :) |
I guess adding a Not sure what the best approach is. I was holding off on it because ES Modules is so new that I am not comfortable supporting it yet. Since I don't use it myself it will be difficult for me to troubleshoot if there are issues with it. |
We're quite heavily invested into both ES6 modules (Currently using standard-things/esm but we want to drop that in favor of native) and Awilix so we'd be happy to guinea pig the setup. Would it perhaps be possible to add it as an option to |
TS does support conditional return types. Here is what you can do: Add an export interface LoadModulesOptions<ESM extends boolean = false> {
// ...
esModules?: ESM
} Change the export interface LoadModulesResult {
loadedModules: Array<ModuleDescriptor>
}
export function loadModules<ESM extends boolean = false>(
dependencies: LoadModulesDeps,
globPatterns: string | Array<string | GlobWithOptions>,
opts?: LoadModulesOptions<ESM>
): ESM extends true ? Promise<LoadModulesResult> : LoadModulesResult When called with When called with |
Great, thanks for the input! I'll give it a try tomorrow and see what I can do! |
I created #211 with a fix for this! |
Since Node supports ES6 modules natively in 14.x and up I tried using it with Awilix, however since Awilix uses
require()
it fails with the following error:I tried some experimenting with dynamic import using
import()
however since this returns a Promise I think the library needs to be rewritten quite a bit in order to support this.Is this something you have planned going forward? I'm happy to help out but I would probably need some pointers as to where to start.
The text was updated successfully, but these errors were encountered: