Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use jQuery in Svelte

Doing this:

import $ from 'jquery';

Shows the error

The $ prefix is reserved, and cannot be used for variable and import names svelte(illegal-declaration)
like image 662
Aneri Emmax Avatar asked Oct 03 '19 12:10

Aneri Emmax


2 Answers

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.

like image 169
CBrown77 Avatar answered Sep 18 '22 01:09

CBrown77


You can just use import as syntax:

import * as $j from 'jquery';

Or as anyName that you can use

like image 32
nircraft Avatar answered Sep 21 '22 01:09

nircraft