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

210
Visualizações
Angular 13 & Datatables.net - Cannot read properties of undefined

So I've been updating an Angular 6 project to Angular 13 and I've got a problem with datatables (datatables.net). When I'm trying to access a page that has one, this error is displayed in my browser's console: Cannot read properties of undefined (reading 'defaults'). Using the console I can see this error is faced on the following code:

protected applyDefaultConfigurationToDatatable(): void {
 /* Set the defaults for DataTables initialisation */
 $.extend(true, $.fn.dataTable.defaults, {
  dom: "<'row'<'col-sm-6'l><'col-sm-6'f>>" +
  "<'row'<'col-sm-12'tr>>" +
  "<'row'<'col-sm-5'i><'col-sm-7'p>>",
  renderer: 'bootstrap'
 });
}

The problem is on this line: $.fn.dataTable.defaults where $.fn.dataTable is undefined.

I'm not sure but from what I saw online while trying to solve my problem it could be related to jQuery and the imports of my JS scripts. I've tried many things to solve my problem such as :

  • Checking I'm importing jQuery only once;
  • Checking the compatibility of my different libs;
  • Checking the order of the imported JS scripts;
  • And many other things...

Here's the part where I import scripts in my angular.json:

"scripts": [
 "node_modules/jquery/dist/jquery.min.js",
 "node_modules/datatables.net/js/jquery.dataTables.js",
 "node_modules/datatables.net-bs/js/dataTables.bootstrap.js",
 "node_modules/datatables.net-fixedcolumns/js/dataTables.fixedColumns.js",
 "node_modules/datatables.net-colreorderwithresize-npm/ColReorderWithResize.js"
],

Here's the part of my package.json that's related to these libs:

"dependencies": {
 "datatables.net": "^1.11.5",
 "datatables.net-bs": "1.11.5",
 "datatables.net-colreorderwithresize-npm": "1.0.4",
 "datatables.net-fixedcolumns": "4.0.2",
 "jquery": "^3.6.0",
 "jquery-color": "1.0.0",
 "jquery-jcrop": "0.9.13",
 "jquery-knob": "1.2.11",
 "jquery-ui-npm": "1.12.0",
 "jquery-validation": "1.16.0",
 "jquery.maskedinput": "1.4.1",
}

I'm stuck on this one problem and any help would be highly appreciated!

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