loopbackio / loopbackio/loopback-next
[BOOT] Not possible to import ESM project files
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 5.1k
- Forks
- 1.1k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 27
Description
Describe the bug
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:
Logs
No response
Additional information
The issue is reproduced in the ToDo example:
- Clone repo, install deps.
- Navigate to
examples/todo. - Run with
npm start
Reproduction
https://github.com/alexbal7/loopback-next/tree/fix/esm-files-import
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in packages/boot/src/booters/booter-utils.ts, focusing on loadClassesFromFiles and its use when bootstrapping the examples/todo application. Reproduce the issue by running npm start from examples/todo after installing dependencies. Done means an ESM-format project can start and load its controllers, models, services, and other project files without the reported startup error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100