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

CommonJS import does not work with moduleResolution: "node" #227

Open
jackbonaguro opened this issue Sep 21, 2022 · 10 comments
Open

CommonJS import does not work with moduleResolution: "node" #227

jackbonaguro opened this issue Sep 21, 2022 · 10 comments

Comments

@jackbonaguro
Copy link

Related to #114

Trying to use the library in a ts-node project. The project needs to use { "moduleResolution": "node" } in its tsconfig.json, as many modules (socket.io specfically) require it.

Example: https://github.com/jackbonaguro/geckos-v2-cjs-example

While geckos.io can be imported in Common.js, changing this line in tsconfig.json breaks the import with the same ERR_REQUIRE_ESM as if it were imported as an ESM module.

@yandeu
Copy link
Member

yandeu commented Sep 22, 2022

I have updated the example. See geckosio/geckos-v2-cjs-example@e788c15

@jackbonaguro
Copy link
Author

@yandeu Thank you, I've pulled that change into my fork but it does not appear to have any effect.

Did you experience the ERR_REQUIRE_ESM before the change, but not after?

@yandeu
Copy link
Member

yandeu commented Oct 5, 2022

I'm not sure. I never use CJS. But the example worked after updating.

Did you also do npm i and npm update?
Does the updated example work when you test it?

@github-actions
Copy link

github-actions bot commented Aug 2, 2023

This issue is stale because it has been open 300 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Aug 2, 2023
@github-actions
Copy link

This issue was closed because it has been stalled for 10 days with no activity.

@singerbj
Copy link

I have updated the example. See geckosio/geckos-v2-cjs-example@e788c15

What do we do if we are using the import in a file that exports a class? Is there a reason commonjs can't just be supported?

@yandeu
Copy link
Member

yandeu commented Aug 23, 2023

Is there a reason commonjs can't just be supported?

I am working on supporting cjs.
It's in the cjs branch.

@yandeu yandeu reopened this Aug 23, 2023
@singerbj
Copy link

singerbj commented Aug 23, 2023

Ah ok cool. I saw his issue closed so I just wanted to check in.

If it's useful, I am trying to get it geckos.io working with nengi (https://github.com/timetocode/nengi). I think they would be a really good pairing, as by default nengi uses websockets rather than UDP.

From my perspective nengi was written with deterministic movement in mind - but naturally I am interested in networked physics. A big part of making that successful based on my research (gaffer on games) is a UDP approach to data transfer.

If I can be of assistance with testing please let me know.

@github-actions github-actions bot removed the Stale label Aug 24, 2023
@yandeu
Copy link
Member

yandeu commented Aug 29, 2023

geckos v2.3.2-dev.0 does now fully support cjs.
I have updated the example https://github.com/geckosio/geckos-v2-cjs-example

@singerbj
Copy link

Awesome! Thanks @yandeu !

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

No branches or pull requests

3 participants