pnotify: Using with webpack crashes a page

I’m using webpack with pnotify (I get pnotify 3.0.0 from npm registry) in my project. So, when I use pnotify 3.0.0 it crashes a site. The reason is here (pnotify.js line 865)

if (root.document.body) {
    do_when_ready();
} else {
    $(do_when_ready);
}

because root is only an object in my case… If I fix it by adding

if (root.document && root.document.body) {

if crashes again later on (jwindow.height() call). I guess

jwindow = $(root);

on 45 line is the reason (where root is only an object)

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 2
  • Comments: 20 (3 by maintainers)

Most upvoted comments

@xtr0 I guess in pnotify mobile module require('./pnotify') is called which caused error in my code. I managed to solve this issue by changing the regex. Thank you for the clue

var PNotify = require("pnotify/src/pnotify.js");
require("pnotify/src/pnotify.mobile.js");
require("pnotify/src/pnotify.buttons.js");
require("pnotify/src/pnotify.desktop.js");

    loaders: [
      { 
        test: /pnotify.*\.js$/, 
        loader: "imports?define=>false,global=>window" 
      },

@nathan818fr , @hperrin Can someone update npm package please? It’s seems to not have this fix =(

For anyone who has trouble with the link @sman591 suggested I had to use the following instead: git+https://github.com/sciactive/pnotify.git#175af26286f584f33282a686191715fadae2f67b

Until a new npm version is released, I got it working with the below config (full gist):

package.json

{
  "devDependencies": {
    "pnotify": "git+https://git@github.com:sciactive/pnotify.git#175af26286f584f33282a686191715fadae2f67b"
  }
}

webpack.config.js

module.exports = {
...
  plugins: [
    new webpack.ProvidePlugin({
      $: "jquery",
      jQuery: "jquery"
    })
  ]
...

index.js

import $ from 'jquery';
import PNotify from 'pnotify';
window.$ = $;
window.jQuery = $;
window.PNotify = PNotify;

@mazavr To workaround this issue you can do the following:

code:

var PNotify = require("pnotify/src/pnotify.js");

// load pnotify modules (I'm using only this two)
require("pnotify/src/pnotify.mobile.js");
require("pnotify/src/pnotify.buttons.js");
// ... other used pnotify modules if any ...

webpack config:

...
    module   : {
        loaders: [
            { test: /pnotify\/src\/.+\.js$/ , loader: "imports?define=>false,global=>window" },
...
       ]
   }

It works for me