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

Switch to ESM only #84

Open
yandeu opened this issue Dec 26, 2021 · 8 comments
Open

Switch to ESM only #84

yandeu opened this issue Dec 26, 2021 · 8 comments
Labels
enhancement New feature or request

Comments

@yandeu
Copy link
Member

yandeu commented Dec 26, 2021

Make nanojsx esm only and drop cjs completely.

@yandeu yandeu added the enhancement New feature or request label Dec 26, 2021
@jrson83
Copy link
Contributor

jrson83 commented Mar 17, 2022

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?

@yandeu
Copy link
Member Author

yandeu commented Mar 18, 2022

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).

@jrson83
Copy link
Contributor

jrson83 commented Mar 18, 2022

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.

@yandeu
Copy link
Member Author

yandeu commented Mar 20, 2022

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

@jrson83
Copy link
Contributor

jrson83 commented Mar 23, 2022

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?

@yandeu
Copy link
Member Author

yandeu commented Mar 23, 2022

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

@fusionstrings
Copy link

I finally got a working example :)

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

Is this something we may use already?

@yandeu
Copy link
Member Author

yandeu commented May 9, 2022

Is this something we may use already?

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants