Meteor JS: Pnotify/Jquery package compatibility - NPM error when trying to import

203 views Asked by At

Wondering if anyone on here has gotten pnotify to work; I am getting the following error (on the server, when building) when trying to use the npm package:

import pnotify from 'pnotify';

Error: jQuery requires a window with a document at module.exports (...\node_modules\jquery\dist\jquery.js:31:12) at s (...\node_modules\pnotify\dist\pnotify.js:6:386)

I'm guessing it has to do with the jquery dependency?

-- [email protected] -- [email protected]

I am using BlazeLayout if it makes a difference...

I have also tried using the atmosphere package, to no avail import { PNotify } from 'meteor/s2corp:pnotify'

Any ideas?

1

There are 1 answers

0
Ramil Muratov On

For minimal notifications:

Add pnotify:

meteor npm install --save pnotify

Import all necessary files and PNotify itself:

import PNotify from 'pnotify'
import 'pnotify/dist/pnotify.css';

Show notifiction:

new PNotify({
  title: 'Regular Notice',
  text: 'Check me out! I\'m a notice.'
});

All together in default meteor bare app:

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';

import PNotify from 'pnotify'
import 'pnotify/dist/pnotify.css';

import './main.html';

Template.hello.onCreated(function helloOnCreated() {
  this.counter = new ReactiveVar(0);
});

Template.hello.helpers({
  counter() {
    return Template.instance().counter.get();
  },
});

Template.hello.events({
  'click button'(event, instance) {
    new PNotify({
      title: 'Regular Notice',
      text: 'Check me out! I\'m a notice.'
    });
    instance.counter.set(instance.counter.get() + 1);
  },
});