Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

207
Vistas
Embedding external script into Next.js application

I've been trying to embed an external JavaScript source into my Next.js application and keep receiving following error:

Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

The code I am trying to use can be found here - The map with the vessel has an option to embed it. So far the component that generates this error looks like this:

<div className={styles['container']}>
    <Script type="text/javascript">
        var width="100%";var height="400"; var mmsi=228402900;
    </Script>
    <Script
        type="text/javascript"
        src="https://www.vesselfinder.com/aismap.js">
    </Script>
</div>

If I copy the embed code into CodePen it works just fine - link to my codepen with the embedded map here.

Does somebody know what could be the problem here?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The issue occurs because the external script is being loaded asynchronously by next/script, thus ignoring the document.write() call present in the script.

From Document.write() MDN documentation:

Note: Using document.write() in deferred or asynchronous scripts will be ignored and you'll get a message like "A call to document.write() from an asynchronously-loaded external script was ignored" in the error console.

You'll need to set the Script strategy to beforeInteractive so the script is added to <head>, and explicitly set the defer property to false to prevent the script from being loaded asynchronously.

<Script
    type="text/javascript"
    src="https://www.vesselfinder.com/aismap.js"
    strategy="beforeInteractive"
    defer={false}
></Script>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda