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

388
Visualizações
Javascript error "_ not defined" with lodash and wordpress

I am having an issue with my wordpress page - as I am always getting this JS error:

Uncaught ReferenceError: _ is not defined

The line of code it is referring to, is the _.noConflict(); statement below. However, as you can see, the lodash is just loaded right above it, and should have provided the _ variable. Any thoughts why this is happening?

<script type='text/javascript' defer src='https://website.com/wp-includes/js/dist/vendor/lodash.min.js'></script>
<script type='text/javascript'>
     window.lodash = _.noConflict();
</script>

I appreciate any hint

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You are loading lodash deferred, which means it'll wait to load, but you're trying to use it immediately. By the time that second part runs, lodash hasn't been loaded yet.

You need to stop deferring the lodash load or wrap the second bit of code in some kind of ready callback that won't run until lodash has been loaded.

about 4 years ago · Juan Pablo Isaza Relatório

0

Try to remove 'defer' in first script tag or add a defer to the second script tag. A 'defer' in script tag means it's executed after the page has finished parsing. Here is a more detailed explanation.

about 4 years ago · Juan Pablo Isaza Relatório

0

You can await for lodash being available.

const sleep = (delay: number) => new Promise((resolve) => setTimeout(resolve, delay));
const getLodash = () =>
  new Promise(async (resolve) => {
    while (_ === undefined) {
      await sleep(100);
    }
    resolve(_);
  });
(async () => {
  window.lodash = await getLodash();
})();
about 4 years ago · Juan Pablo Isaza Relatório
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