rescript-core icon indicating copy to clipboard operation
rescript-core copied to clipboard

@rescript/core does not support ESM.

Open htoooth opened this issue 1 year ago • 2 comments

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/@[email protected][email protected]/node_modules/@rescript/core/src/Core__List.res.js:3
import * as Belt_Array from "rescript/lib/es6/belt_Array.js";

htoooth avatar May 15 '24 23:05 htoooth

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.

jderochervlk avatar May 18 '24 13:05 jderochervlk

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

htoooth avatar May 20 '24 09:05 htoooth

now that core is part of the compiler I guess we can close this one.

tsnobip avatar Mar 07 '25 09:03 tsnobip