Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot include tablesort.number #203

Open
KennyH1 opened this issue Jul 28, 2020 · 3 comments
Open

Cannot include tablesort.number #203

KennyH1 opened this issue Jul 28, 2020 · 3 comments

Comments

@KennyH1
Copy link

KennyH1 commented Jul 28, 2020

My JS file:
import ('../node_modules/tablesort/src/sorts/tablesort.number');
var Tablesort = require('../node_modules/tablesort/src/tablesort');

new Tablesort(document.getElementById('table-id'));

I get this error:
Uncaught (in promise) ReferenceError: Tablesort is not defined at eval (tablesort.number.js?ea31:16) at eval (tablesort.number.js?ea31:26) at Object.XC2G (0.js:10) at __webpack_require__ (runtime.js:791) at fn (runtime.js:151) at fn.t (runtime.js:195)

@tristen
Copy link
Owner

tristen commented Aug 14, 2020

👋 I'm a little confused why you are using both import and require in your JS but my guess is because tablesort.number is defined before the main package, it's not found.

@thely
Copy link

thely commented Dec 8, 2020

I was having this problem even by including it the way it's supposed to work:

var tablesort = require('tablesort');
import "tablesort/src/sorts/tablesort.number.js";

I was able to fix it by adding the following line to the top of tablesort.number.js:

var Tablesort = require("../tablesort.js");

@pableu
Copy link

pableu commented Dec 29, 2020

It worked for me when using require for both (without having to change any of the files). This is my webpack entry point:

window.Tablesort = require('tablesort');
require('tablesort/src/sorts/tablesort.number');

document.querySelectorAll('table[data-sortable]').forEach((e) => new Tablesort(e));

I don't really like that I have to put it into window.Tablesort, but it's good enough for my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants