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

157
Vistas
Is it possible to create script tag without setting a scr?

I have a Javascript code in the string which I want to append to the HTML body. And in that code I want to import some functions from other localization. This is how I am appending Javascript code to the HTML body:

const script = document.createElement('script');
script.setAttribute('type', 'module');
script.text = await view.addScript(); // that function is returning my Javascript code
document.body.appendChild(script);

When I do this I am getting an error: "Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec."

Which I understand. And when I am using appending code other way:

changing:

script.setAttribute('type', 'module');

to

script.setAttribute('type', 'text/javascript');

then I am getting and error: "Cannot use import statement outside a module" which I understand too.

My question is: is it possible to set module Javascript, where code is appended from a string, without setting a src attribute because in my case that src does not exists?

Thanks!

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

0

Ok, I solved the problem. When I code this way:

const script = document.createElement('script');
script.setAttribute('type', 'module');
script.text = await view.addScript(); // that function is returning my Javascript code
document.body.appendChild(script);

What was wrong? My script text included import statement. When a path in import is incorrect then you will get a MIME error. When I gave the correct path, the error was gone and now everything is working :)

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