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

227
Visualizações
webpack-pug js function is not a function

Im new to webpack and pug . Working on a small task and

  • I wrote a function dropDown() in drop.js exported it in index.js file,
  • tried to put it in PUG file but:
  • console writing wether 'function is not defined' or f'unction is not a function'.
  • Please could anyone help me to solve that problem with correct defining js function

here is the link to my webpack.config enter link description here

here is my json file enter link description here

in PUG file i use function like this:

 .searchbox-drop
    button(href="#" data-dropdown='drop1' onclick='dropDown()' aria-controls='drop1' aria-expanded=false class='dropbtn') Вce
      +image('triangle','searchbox-drop__icon' )  

in index.js

import $ from "jquery";
import 'bootstrap';
import './styles/index.scss';
import {dropDown} from './drop.js';





window.dropDown = dropDown();

in drop.js

export function dropDown(){ 
function show() {
  document.getElementById('myDropdown').classList.toggle('show');
}

//close dropdown id the user cliks outside of it
window.onclick = function(e){
if(!e.target.matches('.dropbtn')){
    var myDropdown = document.getElementById('myDropdown');
    if(myDropdown.classList.contains('show')){
      myDropdown.classList.remove('show');
    }
  }
}

}

here is part of PUG plugin in CONFIG file:

new HtmlWebpackPlugin({
filename: 'index.pug' ,
minify: false,
scriptloading:'blocking',
inject:'body'
}),
new HtmlWebpackPugPlugin()

and here is index.pug

include pug/libs/_libs
include pug/_mixins

doctype html
html(lang='en')
include pug/_head
body
include pug/_header
block content

i dont know what i done, but now i even got this error when click on btnenter image description here

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

0

Try to assign the function without invoking it.

window.dropDown = dropDown;

Perhaps this is what you want...

export function dropDown() {
document.getElementById('myDropdown').classList.toggle('show');
}

//close dropdown id the user clicks outside of it
window.onclick = function(e){
if(!e.target.matches('.dropbtn')){
    var myDropdown = document.getElementById('myDropdown');
    if(myDropdown.classList.contains('show')){
      myDropdown.classList.remove('show');
    }
  }
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Thanks to Steven I finally made few changes that solved an issue. in index.js it goes like :

import $ from "jquery";
import 'bootstrap';
import './styles/index.scss';
import {show} from './drop.js';





window.show= show;
window.onclick = function(e){
if(!e.target.matches('.dropbtn')){
    var myDropdown = document.getElementById('myDropdown');
    if(myDropdown.classList.contains('show')){
      myDropdown.classList.remove('show');
    }
  }
} 

and in index.pug:

 onclick = 'show()'
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