-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Improve ESM support through CommonJS #50
Comments
For reference, I made basic adjustments in my fork Just run |
We will be using Should be released on 0.5.14 with this commit 69a130d |
This was referenced Jun 4, 2023
That should be all.
|
For @elysiajs/websocket is migrated to the core package via That should be all for CommonJS, so I'm closing the issue. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At the moment it is not possible to import CommonJS into ESM because the exports defined in
package.json
(of all projects) are sorted incorrectly.Example: (run with
node main.js
)Error: (yes, i've
"type": "module"
in mypackage.json
)The sorting is important.
Node.js
&Deno
apparently check from top to bottom. This means that if it is ESM-context,import
is used instead ofrequire
ornode
.Therefore
node
must move further up and point to CommonJS (in allexports
):Furthermore, type or runtime errors occur when CommonJS is imported into ESM, because
SWC
breaks named exports for ESM in CommonJS build (i.e.module.exports
):❌ SWC
Runtime Error
OR Type error
✅TSC (without SWC)
I can make (or help you with) the changes to
exports
in allpackage.json
, but I don't know how you wanna handleSWC
.An alternative would be to drop CommonJS and only support ESM →
"moduleResolution": "nodenext"
&"type": "module"
(i.e. specify all imports and exports with.js
extension). This would work forNode.js
andDeno
too.The text was updated successfully, but these errors were encountered: