Search code examples
javascripttampermonkey

Get error just Importing library (via @require) in Tampermonkey


I want to import dragtable.js in my Tampermonkey script, but I am getting this error (jQuery is already in my website) :

[Error] ERROR: Execution of script 'DragTable' failed! undefined is not a function (near '...$.widget...') error (anonymous function) (userscript.html:2:186) ... ...

Here is my script:

// ==UserScript==
// @name         DragTable
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://localhost:9010/*
// @require https://rawgit.com/akottr/dragtable/master/jquery.dragtable.js

// @grant        none
// ==/UserScript==

How can I import it without the error? Tks


Solution

  • See dragtable's ReadMe, that library requires both jQuery and jQuery UI.

    From the error listed, it seems that jQuery UI is not present.

    So, your script should be, at a minimum:

    // ==UserScript==
    // @name        DragTable, getting started
    // @match       http://localhost:9010/*
    // @require     http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js
    // @require     https://rawgit.com/akottr/dragtable/master/jquery.dragtable.js
    // @grant        none
    // ==/UserScript==
    


    But, see this other Q&A for a more details about jQuery UI in a userscript.