You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BOOT] Not possible to import ESM project files #10335
There is a problem bootstrapping applications created in the ESM format.
When loopback tries to load all project files (controllers, models, services, etc), it uses utility function loadClassesFromFiles from packages/boot/src/booters/booter-utils.ts which is using CommonJs require() to import projects files. CommonJs cannot require ESM files, only by dynamic importing them using import().
As a result, the similar error appears on startup:
Since loopback supports Node 18+ I believe bootstrap logic can be changed to support dynamic imports. If there is any concerns regarding that, please let me know. Otherwise I will put a draft PR for this change :)
Thanks for raising this! I believe there were discussions on migrating the whole LoopBack project to ESM imports. However, we have not gotten around to doing it.
If the PR is backwards-compatible with CommonJS-like imports, then we'd be happy to review it.
Activity
alexbaluhin commentedon Feb 1, 2024
Since loopback supports Node 18+ I believe bootstrap logic can be changed to support dynamic imports. If there is any concerns regarding that, please let me know. Otherwise I will put a draft PR for this change :)
achrinza commentedon Feb 20, 2024
Thanks for raising this! I believe there were discussions on migrating the whole LoopBack project to ESM imports. However, we have not gotten around to doing it.
If the PR is backwards-compatible with CommonJS-like imports, then we'd be happy to review it.