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

@rescript/core does not support ESM. #220

Open
htoooth opened this issue May 15, 2024 · 2 comments
Open

@rescript/core does not support ESM. #220

htoooth opened this issue May 15, 2024 · 2 comments

Comments

@htoooth
Copy link

htoooth commented May 15, 2024

When I compile rescript into JavaScript and have Node.js run it, I found that the @rescript/corewas not set as a esmodule. When I manually changed the package.json in the core to type: module, everything worked properly.

(node:46659) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/Users/projects/rescript-message/node_modules/.pnpm/@rescript+core@1.3.0_rescript@11.1.0/node_modules/@rescript/core/src/Core__List.res.js:3
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";
@jderochervlk
Copy link
Contributor

You need to set the file extension to .mjs or .res.mjs to opt into ESM for dependent packages. If we were to set "type": "module" in the package.json for Core it would mean ESM would be the default and for CJS support you would need to set the file extension to .cjs. Opting into ESM is probably the best path now, but the docs could probably be clearer around this. Soon this library will be part of the compiler, so it will be easier to keep everything aligned with ESM/CJS.

@htoooth
Copy link
Author

htoooth commented May 20, 2024

@jderochervlk Thank you. You've saved me time.

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

2 participants