list.js icon indicating copy to clipboard operation
list.js copied to clipboard

How am I suppose to import list.js with es6 and webpack ?

Open smknstd opened this issue 7 years ago • 16 comments

I would have expect a export default List;

then I could do import List from 'list.js';

How am I suppose to do that ? thanks in advance !

smknstd avatar Oct 25 '17 16:10 smknstd

Simply put import List from 'list.js'; on top of your file and use the library using new List().

thedaviddias avatar Nov 13 '17 16:11 thedaviddias

@thedaviddias Thanx for answering :) That is precisely what I'd expect but it seems like not working (I'm using version 1.5.0 of list.js)

:/

As said, I had to add manually export default List; to the end of the minified file as I heard here https://github.com/javve/list.js/issues/542#issuecomment-324858891 to make it work...

smknstd avatar Nov 13 '17 17:11 smknstd

u can also try window.ListJS = require('list.js')

ctf0 avatar Mar 18 '18 13:03 ctf0

I did what @ctf0 suggested, except mine was window.List = required('list.js') so that it's consistent with the name in the documentation.

victoragung avatar Mar 28 '18 12:03 victoragung

For me even the window.List = required('list.js') gives me an empty object - same as import List from 'list.js'; Does not work in my case :(

binarykiwi avatar May 31 '18 13:05 binarykiwi

@binarykiwi looks like you're typing required instead of require. Remove the d and see if that helps.

fakefarm avatar Jul 22 '18 13:07 fakefarm

@fakefarm no, that doesn't help either. Still this error: Uncaught ReferenceError: List is not defined

binarykiwi avatar Sep 18 '18 09:09 binarykiwi

Hmm, yeah this sounds like a problem. Could someone provide me with an example project for this issue? So I can try it out myself locally.

javve avatar Dec 18 '18 21:12 javve

import List from 'list.js'; at the top of src/index.js works fine, @javve. (list.js 1.5.0)

I've had this error too, but I had npm installed listjs where it should have been list.js.

tilsammans avatar Dec 23 '18 23:12 tilsammans

I made this work creating a new file class.list.js

const List = require('list.js/src/index');

export default List;

And i was able to use it in my own file:

import List from './class.list';

I hope this helps

gpbeer avatar Mar 21 '19 10:03 gpbeer

The following works for me:

npm install list.js
import List from 'list.js;

mounted: function () {
    // Init list
    new List('myList', {
        valueNames: ['country', 'percent'],
        page: 3,
        pagination: true
    });
}

anselal avatar Jan 15 '20 10:01 anselal

This should be via CDN and documented.

cekvenich2 avatar Jun 06 '21 14:06 cekvenich2

try this require('./file.js').list

Joshua-Enrico avatar Aug 03 '21 11:08 Joshua-Enrico

I've tried all of the above suggestions with no luck and am continually met with the following error: ReferenceError: Can't find variable: List. Is there a new approach to using this library with Webpack? Can this get documented officially?

Justintime50 avatar Mar 19 '22 06:03 Justintime50

This worked for me. import * as List from 'list.js';

monamii avatar Jul 25 '22 16:07 monamii

Any news ?

gotexx1 avatar Mar 03 '23 13:03 gotexx1