Skip to content

Migrate from cjs to esm - #154

Draft
barthofu wants to merge 20 commits into
mainfrom
feat/esm
Draft

Migrate from cjs to esm#154
barthofu wants to merge 20 commits into
mainfrom
feat/esm

Conversation

@barthofu

@barthofu barthofu commented Feb 11, 2024

Copy link
Copy Markdown
Owner

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

zumbiepig commented Jan 21, 2025

Copy link
Copy Markdown

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.

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