Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

145
Visualizações
Importing a JavaScript module loaded from a CDN in a StackBlitz module

I'm working on a simple Three.js example in StackBlitz, loading this library off of a content delivery network.

If I place the import statement inside a script tag embedded in the HTML document, it's able to resolve the package and everything works as desired:

<html>
  <head>
    <meta charset="UTF-8" />
  </head>
  <body>
    <script type="module">
      import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.126.0/build/three.module.js';          
      // TODO: some code using Three.js...
    </script>
  </body>
</html>

But the boilerplate for setting up a 3D scene can get a bit verbose, so I'd like to offload some of it to my own module file.

If I make a script.js file like so:

import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.126.0/build/three.module.js';

function foo() {}
export { foo }

...and then reference it from a script tag like so:

<html>
  <head>
    <meta charset="UTF-8" />
    <script src="script.js" type="module"></script>
  </head>
  <body>
  </body>
</html>

...or like so:

<html>
  <head>
    <meta charset="UTF-8" />
    <link rel="stylesheet" type="text/css" href="styles.css" />
  </head>
  <body>
    <script type="module">
        import foo from '/script.js';
    </script>
  </body>
</html>

Then I get the following error message:

Error in 0.126.0/build/three.module.js". Relative references must start with either "/", "./", or "../".

Failed to resolve module specifier "et/npm/three@0.126.0/build/three.module.js". Relative references must start with either "/", "./", or "../".

Note that the module specifier it quotes is missing the first 22 characters of the URL. So it seems like StackBlitz is somehow extracting just part of the path and trying to load from that incomplete address.

Is there something I can do to avoid this behaviour, or load my module in a way that's more compatible with how StackBlitz handles modules?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda