JSSoup icon indicating copy to clipboard operation
JSSoup copied to clipboard

JSSoup is not a constructor

Open ghost opened this issue 3 years ago • 6 comments

Hey! I am trying to use JSSoup in ES6 node.js with modules, but it keeps giving me a JSSoup is not a constructor issue. Any help on this would be appreciated.

ghost avatar May 17 '22 01:05 ghost

make sure you import it correctly

var JSSoup = require('jssoup').default;

b1acKr0se avatar Jun 07 '22 08:06 b1acKr0se

user@pop-os:~/vcs/int/jssoup-test$ cat index.js 
import JSSoup from 'jssoup'; 

const html = `
<p>one</p><p>two</p>
<p>three</p>
`;

const soup = new JSSoup(html);

user@pop-os:~/vcs/int/jssoup-test$ node index.js 
file:///home/user/vcs/int/jssoup-test/index.js:8
const soup = new JSSoup(html);
             ^

TypeError: JSSoup is not a constructor
    at file:///home/user/vcs/int/jssoup-test/index.js:8:14
    at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:409:24)
    at async loadESM (node:internal/process/esm_loader:85:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

Node.js v17.9.0

platform pop!os Linux AMD64

SaulMoonves avatar Jun 23 '22 16:06 SaulMoonves

I am also having the same issue. I have tried both import statements listed on the docs, Node JS doesn't like either one.

Anyone have working code with this import??

ccarlton96 avatar Aug 30 '22 22:08 ccarlton96

I am having the same issue as well, even if my fetching function returns a valid response

LuisC360 avatar Oct 07 '22 19:10 LuisC360

you need one of the following because the developer exported the name as "default":

ES6+

import JSSoupt from 'jssoup'
const Soup = JSSoup.default

const mysoup = new Soup(<form>)

ES6+

import JSSoup from 'jssoup'

const mysoup = new JSSoup.default(<form>)

ES5

var JSSoup = require('jssoup').default

const mysoup = new JSSoup(<form>)

dustingraves avatar Mar 15 '23 17:03 dustingraves