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

[Build] Support module resolution node16 and nodeNext #13797

Open
RaananW opened this issue May 2, 2023 · 7 comments
Open

[Build] Support module resolution node16 and nodeNext #13797

RaananW opened this issue May 2, 2023 · 7 comments

Comments

@RaananW
Copy link
Member

RaananW commented May 2, 2023

To support the new module resolutions (introduced in ts 4.7) we will need to add extensions to the declaration files (just like we are adding to the generated .js files).
This might require us to change the repository structure (adding .js to the imports in our libraries), or we will need to parse all generated files and add .js manually.

From initial tests - doing that will not break the current moduleResolution used (i.e. node), so there is no back-compat issue here. This, however, needs to be tested as part of the implementation of this issue.

Copy link

github-actions bot commented Mar 14, 2024

This issue has been automatically staled because it has been inactive for more than 14 days. Please update to "unstale".

@github-actions github-actions bot added stale and removed stale labels Mar 14, 2024
Copy link

This issue has been automatically staled because it has been inactive for more than 14 days. Please update to "unstale".

@github-actions github-actions bot added the stale label Mar 30, 2024
@RaananW RaananW modified the milestones: Future, 8.0 May 13, 2024
@RaananW
Copy link
Member Author

RaananW commented May 13, 2024

bumping this up. will tackle this for 8.0

@RaananW
Copy link
Member Author

RaananW commented May 14, 2024

For future reference - the best solution here, while maintaining back-compat, is to have two sets of types, one in the core directory, and one in ./nodenext/*. The second one has .js in all declarations as well.
The way to automate the usage is to add "exports" to package.json:

"exports": {
        "./*":  "./nodenext/*"
    },

What this will do is will force using the new version when using nodenext (or node16 or bundler) as module resolution. Otherwise it will be ignored (as module resolution - node - doesn't use the exports keyword. Sounds a bit off, as one is a ts feature and one is a js feature, but it is really the case...)

Note that when using webpack with nodenext, you will need to add this to config.resolve:

 extensionAlias: {
            ".js": [".js", ".ts"],
            ".jsx": [".jsx", ".tsx"],
        },

Otherwise webpack will not resolve the ts files correctly.

@chase-moskal
Copy link

chase-moskal commented May 15, 2024

Otherwise webpack will not resolve the ts files correctly.

since my team uses rollup instead of webpack, i don't understand the purpose of this extensionAlias webpack config -- but it prompts me to ask here (regarding this new nodenext distribution):

  1. can we expect to use an ordinary out-of-the-box standard modern node resolution just like any other modern package?
  2. or will we have to setup some unique config to ingest babylon?

of course, i'm hoping it's the first option😅

as a potentially-related side note -- babylon's reliance on side-effects is constantly hurting us, as we often have to do a bunch of debugging on a random error, and it basically takes a stroke of luck to realize that it's because we're missing some module's necessary side-effect -- i thought that there was once a roadmap item to have this fixed, but i can't seem to find it anymore -- i just wonder if addressing this problem could be a consideration that might be related to this module work? -- if it cannot be fixed, maybe we could start mapping and documenting all the modules that require side effects, and all the modules that provide side effects, to make the process of hunting down the necessary relationships much easier.. just let me know if it would be useful for me to create a separate issue about this.

thanks for all your hard work, we really appreciate it, it makes our soon-to-be-announced open source game project possible ❤️

@RaananW
Copy link
Member Author

RaananW commented May 16, 2024

I will do whatever in my powers to never make it option 2.
This is the reason behind technically compiling the framework twice, one for nodenext and one for node. This way everyone gets a version of the framework that will be consumed automatically.

Now, regarding side effects - I never hid my opinion about the need to ditch side effects. There is a small issue with doing that in regards to our current package architecture, because this will cause some breaking changes to people using the es6 packages already. We are constantly finding new smart ways of solving this and evaluating them. When we find the best way we will deliver a side-effect-free version of the framework.

@sebavan sebavan removed the stale label May 21, 2024
Copy link

This issue has been automatically staled because it has been inactive for more than 14 days. Please update to "unstale".

@github-actions github-actions bot added the stale label Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants