Aneri Emmax
Aneri Emmax

Reputation: 202

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)

Upvotes: 20

Views: 24342

Answers (3)

Snailedlt
Snailedlt

Reputation: 734

This should do the trick:

import jQuery from 'jquery'

relevant SO answer

Upvotes: 7

CBrown77
CBrown77

Reputation: 557

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.

Upvotes: 14

nircraft
nircraft

Reputation: 8478

You can just use import as syntax:

import * as $j from 'jquery';

Or as anyName that you can use

Upvotes: 20

Related Questions