sciactive / pnotify

Beautiful JavaScript notifications with Web Notifications support.
https://sciactive.com/pnotify/
Apache License 2.0
3.65k stars 514 forks source link

Error: Can't resolve 'pnotify/dist/es' in "alpha.3" #340

Closed nasatome closed 5 years ago

nasatome commented 6 years ago

The library is not loaded correctly (I'm not an expert in the area so I do not know if it's a bug or a technical problem of mine)

Using the version in my package.json "pnotify": "^ 4.0.0-alpha.2" did not have any problem, but I made a "npm update" and it was updated to the "pnotify" version: "^ 4.0.0- alpha.3 "and I stop loading the library.

ERROR in ./resources/assets/js/bootstrap.js Module not found: Error: Can't resolve 'pnotify/dist/es' in '/var/www/html/resources/assets/js' @ ./resources/assets/js/bootstrap.js 29:0-38 @ ./resources/assets/js/app.js @ multi ./resources/assets/js/app.js

I use ES6 with Laravel Mix (WebPack Wrapper), but I'm loading the library from the bootstrap.js.

import PNotify from 'pnotify/dist/es';
window.PNotify = PNotify;
PNotify.defaults.styling = "material";
PNotify.defaults.icons = "material";

with that it was enough for it to load and function in the "alpha.2" but now it does not work in the "alpha.3"

nasatome commented 6 years ago

I incorporate the files:

index.js

import PNotify from"./PNotify.js";import PNotifyAnimate from"./PNotifyAnimate.js";import PNotifyButtons from"./PNotifyButtons.js";import PNotifyCallbacks from"./PNotifyCallbacks.js";import PNotifyConfirm from"./PNotifyConfirm.js";import PNotifyDesktop from"./PNotifyDesktop.js";import PNotifyHistory from"./PNotifyHistory.js";import PNotifyMobile from"./PNotifyMobile.js";import PNotifyNonBlock from"./PNotifyNonBlock.js";import PNotifyStyleMaterial from"./PNotifyStyleMaterial.js";export default PNotify;
//# sourceMappingURL=index.js.map

and index.js.map

{"version":3,"sources":["index.js"],"names":["PNotify","PNotifyAnimate","PNotifyButtons","PNotifyCallbacks","PNotifyConfirm","PNotifyDesktop","PNotifyHistory","PNotifyMobile","PNotifyNonBlock","PNotifyStyleMaterial"],"mappings":"OAAOA,YAAa,sBACbC,mBAAoB,6BACpBC,mBAAoB,6BACpBC,qBAAsB,+BACtBC,mBAAoB,6BACpBC,mBAAoB,6BACpBC,mBAAoB,6BACpBC,kBAAmB,4BACnBC,oBAAqB,8BACrBC,yBAA0B,2CAElBT","file":"index.js","sourceRoot":"../"}

And now it works ( without icons )

hperrin commented 6 years ago

The index file was removed in alpha.3, since it was loading modules that had side effects, and thus was including all of the js in bundled files. So, in alpha.2, you could do this:

import {PNotify, PNotifyButtons} from 'pnotify/dist/es';

but, Rollup would rightly include all of the modules. In alpha.3, you can do this:

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

and Rollup will only include the Buttons module.

Webpack didn't do any analysis of the code, so it wouldn't include the extra modules, but that behavior differs from how it would work in pure ES modules, so I felt it better to remove the index file and only have intended behavior.

nasatome commented 6 years ago

Now I understand, it was intentional elimination of index.

Thanks!, case closed, the problem of the icons was that I was not loading the "Material Icons" correctly (I used to load them in an automatic, and not now)

I preferred to add the fontawesome icons and that's it, solved.