nano icon indicating copy to clipboard operation
nano copied to clipboard

Switch to ESM only

Open yandeu opened this issue 3 years ago • 8 comments

Make nanojsx esm only and drop cjs completely.

yandeu avatar Dec 26 '21 13:12 yandeu

Hey @yandeu, I tried setting up a project with SSR and "type": "module" inside package.json.

To reduce entry point size, I'd like to import every export from nano-jsx/lib/<component> instead of importing everything from nano-jsx. I changed every import from lib to esm folder for testing, but now the commonjs server files also use the esm files with require so it naturally throws [ERR_REQUIRE_ESM]: require() of ES Module server\assets\index.page.ab0d9bb1.js not supported.

I thought when pointing to nano-jsx it would maybe load from esm automatically for client, but it still loads from nano-jsx/lib/index.

Is it actually possible to already use the esm bundle in the current state of development with SSR?

jrson83 avatar Mar 17 '22 23:03 jrson83

It is ready.

But I believe Webpack can't bundle Node.js modules yet. So you can't use it Isomorphic. At least I failed setting it up.

To use it on the server you can use the node12 option of the ts compiler (typescript@next).

yandeu avatar Mar 18 '22 10:03 yandeu

Oki, I didn't use Webpack, I used Vite with vite-plugin-ssr which is using ESBuild to compile Typescript. I gonna read the docs again and see if I can get it working.

jrson83 avatar Mar 18 '22 15:03 jrson83

I finally got a working example :) https://github.com/nanojsx/nano-jsx-esm-example

yandeu avatar Mar 20 '22 12:03 yandeu

I finally got a working example :) https://github.com/nanojsx/nano-jsx-esm-example

Nice, thanks. I also tried but couldn't get it working.

Will you remove cjs support in the future?

jrson83 avatar Mar 23 '22 19:03 jrson83

In the future, I will make esm the default. But I will still ship both.

yandeu avatar Mar 23 '22 19:03 yandeu

I finally got a working example :)

https://github.com/nanojsx/nano-jsx-esm-example

Is this something we may use already?

fusionstrings avatar May 09 '22 19:05 fusionstrings

Is this something we may use already?

Yes

yandeu avatar May 09 '22 19:05 yandeu