pnotify not working in my symfony 4 and webpack using yarn

515 views Asked by At

I'm using symfony 4.2; I'm also using webpack and yarn to manage my assets.
I have added the package using:

yarn add pnotify

I can see the files in node_modules. I have required both the css and the js files:

require('pnotify/dist/PNotifyBrightTheme.css');
require('pnotify');

When I run this command I get the error below:

yarn run encore dev

Can't resolve pnotify in app.js

If I change the require to this it builds successfully:

require('pnotify/dist/umd/PNotify');

When I try to test with twig like this, I get the error below:

<script type="text/javascript">
  $(document).ready(function() {
    (new PNotify({
      title: 'Regular Notice,
      text: 'Check me out! I\'m a notice.',
      type: 'info',
      styling: 'bootstrap3'
    }));
  });
</script> 
> vendor.js:7803 Uncaught ReferenceError: PNotify is not defined
at HTMLDocument.<anonymous> (create:513)
at mightThrow (vendor.js:7510)
at process (vendor.js:7578)
1

There are 1 answers

0
Coffeverton On

It seems that the correct way is this:

import PNotify from 'pnotify/dist/es/PNotify';
import PNotifyButtons from 'pnotify/dist/es/PNotifyButtons';

As per this link