-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Unable to use Store server-side due to ESM #967
Comments
Hmm, yeah. Not sure how I overlooked that! I'm not totally in favour of the first option — I think it's better if there's only one way to access it, otherwise it gets confusing, and we wouldn't want people accidentally importing directly from A third option would be to rename |
On second thoughts that would be a breaking change for people already importing from |
My 2¢ I converted my modules to *.mjs & it was a relatively smooth transition to native nodejs ES6 modules. For posterity, to paraphrase their justification, it was the "least bad" solution & distinguishes between files using ES module & node modules. *.mjs files also work seamlessly when using rollup or node. Maybe I'm misunderstanding your reticence, but it's my understanding that I'm not familiar about the umd use case, but it seems natural to transpile |
By 'breaking change' I mean that anyone doing this... import { Store } from 'svelte/store.js'; ...would find their apps misbehaving if there was no longer an ES module at that location. Maybe I'm the only person who does that so I shouldn't worry, but technically it violates semver... |
You could have a deprecated |
My suggestion for option 2 would be for // ES Module
const { Store } = require('svelte/store')
// Bundled / compiled
require('svelte/ssr/register')({ store: true });
const { Store } = require('svelte/store'); Not a great solution, but somewhat intuitive with the Another alternative, could put it under the const { Store } = require('svelte/ssr/store') But, universal is probably the best bet, so I'm for |
To add in favor of I'd be willing to make a PR, but it would be the first thing I've ever done with Rollup. |
As of 1.49.2 the package exposes svelte/store.umd.js |
Just to clarify — that file creates a new global So you can use it like so: <script src='https://unpkg.com/svelte/store.umd.js'></script>
<script>
var store = new svelte.Store();
</script> |
I'm really liking
svelte/store
, but it's a little tricky to get it working server-side due to ES modules. I was able to get it working with the following, but I'm wondering if there are other possibilities:I was thinking there are a couple of possibilities:
const { Store } = require('svelte')
server-sidesvelte/store
withsvelte/ssr/register
The text was updated successfully, but these errors were encountered: