Estoy tratando de mostrar una notificación simple en el navegador web usando PNotify en la página html de thymeleaf.
He agregado el siguiente webjar a mi pom.xml.
<dependency> <groupId>org.webjars.npm</groupId> <artifactId>pnotify__core</artifactId> <version>${pnotify.version}</version> </dependency> <dependency> <groupId>org.webjars.npm</groupId> <artifactId>pnotify__mobile</artifactId> <version>${pnotify.version}</version> </dependency>PNotificar versión = 5.2.0
En mi HTML, he incluido -
<link th:href="@{/webjars/pnotify__core/dist/PNotify.css}" rel="stylesheet" /> <link th:href="@{/webjars/pnotify__mobile/dist/PNotifyMobile.css}" rel="stylesheet" /> <script th:src="@{/webjars/pnotify__core/dist/PNotify.js}"></script> <script th:src="@{/webjars/pnotify__mobile/dist/PNotifyMobile.js}"></script>He confirmado que todos estos recursos se cargan correctamente con el código de estado 200. En mi javascript, estoy tratando de hacer lo siguiente:
<script type="module"> import { defaultModules } from '../webjars/pnotify__core/5.2.0/dist/PNotify.js'; </script>Pero recibo un error de seguimiento en la consola del navegador.
Uncaught SyntaxError: import not found: defaultModulesVerifiqué en el navegador que el archivo existe en http://localhost:8080/webjars/pnotify__core/5.2.0/dist/PNotify.js
No tengo ni idea y no puedo encontrar ninguna ayuda en los foros. ¿Alguien puede ayudarme y compartir algunos consejos para depurar?
Finalmente, pude hacerlo funcionar haciendo los siguientes cambios. Las dependencias en pom.xml eran las mismas. En archivo HTML, agregado siguiendo css y js
<link th:href="@{/webjars/pnotify__core/dist/PNotify.css}" rel="stylesheet" /> <link th:href="@{/webjars/pnotify__bootstrap4/dist/PNotifyBootstrap4.css}" rel="stylesheet" /> <script th:src="@{/webjars/pnotify__core/dist/PNotify.js}"></script> <script th:src="@{/webjars/pnotify__bootstrap4/dist/PNotifyBootstrap4.js}"></script>En el javascript, usé el siguiente fragmento de código (sin ninguna importación)
PNotify.defaultModules.set(PNotifyBootstrap4, {}); PNotify.success({ title: 'Success!', text: 'That thing that you were trying to do worked.' });