Skip to content
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

Migrate from cjs to esm #154

Draft
wants to merge 20 commits into
base: main
Choose a base branch
from
Draft

Migrate from cjs to esm #154

wants to merge 20 commits into from

Conversation

barthofu
Copy link
Owner

@barthofu barthofu commented Feb 11, 2024

This draft PR is an attempt to finaly migrate from CJS to ESM.

Problem(s)

The most important problem is that ts-node (for dev) doesn't support tsconfig.paths aliases resolution in ESM. I've managed to quite fix that using a custom loader (./loader.js).

We also want to keep the commands and events HMR.

What I've done so far

  1. Switch tsconfig.target and tsconfig.module to esnext
  2. Complete the tsnode config block in the tsconfig json file
  3. Change the case dep which was CJS-only with change-case.
  4. Remove automatic DI in constructors in favor of a resolveDependencies
    4.1 because of the error Cannot access X before initialization
  5. but now i got a max memory call stack error...

Solutions

  1. find a good loader file and make all of this work in ESM (currently being tested)
  2. find a way to build ts -> js on watch and serve the dev process from the js files, while keeping the HMR and speed advantages

Notes

  • A lot of older attempts are stashed on @barthofu coder workspace.

@barthofu barthofu self-assigned this Feb 11, 2024
@barthofu barthofu changed the title CJS -> ESM Migrate from cjs to esm Feb 11, 2024
Base automatically changed from version/2.3 to main March 4, 2024 10:41
@zumbiepig
Copy link

@barthofu @Mr-Artemus

What is HMR? Using something like Deno or Bun could solve most of these concerns (hot reloading, building, speed).

I fixed most of these issues on my fork, but not the hot reloading.

Can you clarify what the HMR is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants