microsoft/just

just-task config.ts should support ESM configs

dzearing opened this issue · 5 comments

Right now, just-scripts only works with commonjs configs. Given how the ecosystem is moving to esm, this will become a point of frustration.

If you have a package with type: "module" set right now, you'd expect just.config.js to be an ESM.

just-task will throw:

yarn run v1.22.17
warning package.json: No license field
$ just-scripts build
[5:06:17 PM] x Invalid configuration file: D:\git\cloudpack2\packages\path-utilities\just.config.js
[5:06:17 PM] x Error: Error [ERR_REQUIRE_ESM]: require() of ES Module D:\git\cloudpack2\packages\path-utilities\just.config.js from D:\git\cloudpack2\node_modules\just-task\lib\config.js not supported.
Instead change the require of just.config.js in D:\git\cloudpack2\node_modules\just-task\lib\config.js to a dynamic import() which is available in all CommonJS modules.
    at Object.readConfig (D:\git\cloudpack2\node_modules\just-task\lib\config.js:30:34)
    at Object.<anonymous> (D:\git\cloudpack2\node_modules\just-task\lib\cli.js:37:31)
    at Object.<anonymous> (D:\git\cloudpack2\node_modules\just-scripts\lib\cli.js:3:1)
    at Object.<anonymous> (D:\git\cloudpack2\node_modules\just-scripts\bin\just-scripts.js:2:1)

I think the require statement can change to an async import, but that will also require some shuffling in the CLI to await on results (or Promise chain.) Plus I'm not sure how this will affect importing commonjs results - that will still need testing.

This is not an issue if you use TS with a commonjs module output, but I've been trying to remove cjs output in new code.

Any word here? I'm also running into this, and would like to use Just with ESM pretty soon. We have a big monorepo that uses Just everywhere, and we'll eventually need to convert to ESM.

we are also running into this ATM

I managed to make it work with these simple tweaks, it might be more complicated than that ... would be great to ship this.

image

https://github.com/microsoft/fluentui/pull/30582/files#r1499133479

we are also running into this ATM

I managed to make it work with these simple tweaks, it might be more complicated than that ... would be great to ship this.

image [microsoft/fluentui#30582 (files)](https://github.com/microsoft/fluentui/pull/30582/files#r1499133479)

Thank you so much that worked, here is a pnpm patch file if anyone wants to add this to their repo fast https://gist.github.com/spookyuser/c295d14654004d2ca7b735dce4e012e9