Meteor package : $ is not defined

Hi all,
I am a new user (some weeks) of Meteor.
I try to write a Meteor package for my application. This package is expected to use jQuery, but I’m unable to make it works :frowning:

package.js:

Package.describe({
    name: 'pwi:ronin-core-prefs',
    version: '1.0.0',
    summary: 'User prefences management',
    git: '',
    documentation: 'README.md'
});

Package.onUse( function( api ){
    configure( api );
    api.mainModule( 'ronin-core-prefs.js' );
});

Package.onTest( function( api ){
    configure( api );
    api.use('tinytest');
    api.mainModule( 'ronin-core-prefs-tests.js' );
});

function configure( api ){
    api.versionsFrom( '1.8.1' );
    api.use( 'ecmascript' );
    api.use( 'jquery' );
    api.use( 'pwi:ronin-core-ui' );
}

ronin-core-prefs.js

import { Ronin } from 'meteor/pwi:ronin-core';

Ronin.prefs = {};

import './lib/user_prefs.js';

user_prefs.js

import { Meteor } from 'meteor/meteor';
import { Tracker } from 'meteor/tracker';
import { Ronin } from 'meteor/pwi:ronin-core';

//<nothing>                         // ReferenceError: $ is not defined
//import 'jquery';                  // ReferenceError: $ is not defined
//import 'meteor/jquery';           // ReferenceError: $ is not defined
//import { $ } from 'meteor/jquery';            // TypeError: Cannot read property 'extend' of undefined
//import { jQuery as $ } from 'meteor/jquery';  // TypeError: Cannot read property 'extend' of undefined

I expected that declaring “api.use( ‘jquery’ );” would be enough, but it is not the case.
And I don’t understand how importing jQuery into my user_prefs.js script.

Could someone be kind enough to give some help or hint or pointer ?
Thanks in advance.

Regards
Barbaps

This doesn’t answer your question, but you possibly may find that jQuery is no longer needed.

http://youmightnotneedjquery.com/

Hi,
Indeed.
Yes.

Long answer is : I have found functions which could replace the “$.extend()” I need.
But developing this application with Meteor is a way for me to learn my first JS framework. The doc says that one can use a NPM module as a resource in a Meteor package. So I suppose that I am doing something wrong, and I would like to know what and to understand why…

Pierre

Maybe I will be able to answer my own question :
Is it possible that some packages be only available on client side, and are not on server side ?
And if yes, how do we know which are available on client side only, and which are available on both side ?

At this point you should be using jquery via npm, not the Atmosphere package.

Hi Barbaps, welcome to the forums!
Recently the jquery package was changed to only use the version from npm. So to get your project to work you will need to install jquery from npm with:

meteor npm install jquery

then import { $ } from 'meteor/jquery' will work fine

Yes, this is one of the advantages of atmosphere packages, that they can have separate server and client components

Looks like jquery is client only:

2 Likes