How do I use jQuery in Svelte

Viewed 14553

Doing this:

import $ from 'jquery';

Shows the error

The $ prefix is reserved, and cannot be used for variable and import names svelte(illegal-declaration)
2 Answers

You can just use import as syntax:

import * as $j from 'jquery';

Or as anyName that you can use

I noticed that if JQuery is already available globally, then you can access it via window.$ instead of just $ and the svelte compiler won't complain.

Related