How to use datatable with vue 3 + vite ?

How to use datatable with vue 3 + vite ?

safi_okzsafi_okz Posts: 4Questions: 3Answers: 0

I am trying to use datable with vue 3 + vite but browser gives us this error "Uncaught (in promise) TypeError: $(...).DataTable is not a function"

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,534Questions: 1Answers: 10,475 Site admin

    We don't have specific documentation for that setup yet I'm afraid, so perhaps you could show us how you have things setup? A small repo that reproduces the issue would be really useful.

    Also, I've been working on updating DataTables to support ES modules recently which will help with Vite (I presume you have configured it with a UMD loader of some sort at the moment to even have a chance for it to work).

    Allan

  • jbnvjbnv Posts: 9Questions: 4Answers: 1
    Answer ✓

    Try adding this build setup to your vite.config.js:

    import { defineConfig } from "vite";
    
    export default defineConfig({
      build: {
        rollupOptions: {
          external: ["jquery"],
          output: {
            globals: {
              jquery: ["$", "window.jQuery"],
            },
          },
        },
      },
      // ...
    });
    
Sign In or Register to comment.