Quiero usar EditorJS en mi proyecto. Así que he creado un archivo HTML después de leer la documentación. Aquí está el archivo llamado index.html :
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Home</title> </head> <body> <div id="editorjs"></div> <script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script> <script> import EditorJS from '@editorjs/editorjs' const editor = new EditorJS('editorjs') </script> </body> </html> Después de abrir el archivo en el navegador, EditorJS no aparece y este mensaje se imprime en la consola: Error de Uncaught SyntaxError: Cannot use import statement outside a module .
¿Cómo arreglar este problema?
El script no es un módulo de tipo, use:
<script type="module"> <!DOCTYPE html> <html lang="en"> <head> <script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Home</title> </head> <body> <div id="editorjs"></div> <script> const editor = new EditorJS({ autofocus: true }); </script> </body> </html>Cuando agrega una etiqueta de secuencia de comandos en su archivo HTML, no necesita importar la biblioteca nuevamente, ¡simplemente puede comenzar a usarla!