ActionHero and ES Modules -> Changes Needed on the Horizon. #1571
-
Currently, the design of Actionhero is that it does a lot of dynamic requires. This makes it incompatible with using ES modules as your project's type as defined in the package.json. Currently, the design (which is still in flux but approaching stability) is that you can use ES modules natively in Node, except that there are restrictions on how it interops with CommonJS. In particular, one thing that is not possible is that the dynamic require cannot be done in all circumstances. However, when using ES Modules, you will have access to the import function, that will sort of take the place with the dynamic require. One major difference here is that the import is always asynchronous (promise). Actionhero would have to be rewritten with this restriction in mind. Loading modules dynamically at the beginning should still be possible, but the code would have to be adjusted for this to work properly with an async import. This should not be a problem with Typescript, as typescript has a build process. This would only affect those who want to write Actionhero using ES modules as they will appear in their final form. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I think a really good starting pace for this work (which we should totally undertake) is to start by replacing all ‘require’ statements with ‘await import’ (if they do need to be dynamically resolves). I can’t think of a reason of the top of my head where this would would cause any problems... We may have been lazy in a few places using ‘require’ for json files, but those can be moved to fs. |
Beta Was this translation helpful? Give feedback.
-
@jamespedid is this something you will be able to undertake? |
Beta Was this translation helpful? Give feedback.
-
This work is completed in #1614, except for the config system |
Beta Was this translation helpful? Give feedback.
This work is completed in #1614, except for the config system