question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is the right way to create instance of jsom while working with ES6?

See original GitHub issue

I use jsdom 13.2 and ES6. On npm page the following example is given:

const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);

When I changed this code to:

import { jsdom } from "jsdom";
const { JSDOM } = jsdom;
const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);

I got error.

The only way I made it work is:

import { JSDOM } from 'jsdom';
const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);

However, I didn’t find anyone used the same way. Is this a right way?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
PavelKastornyycommented, Feb 18, 2019

@domenic Besides, node.js developers already work at adding es6 modules and it is already possible to use it in experimental mode. So, again, this issue does make sense.

4reactions
domeniccommented, Feb 18, 2019

jsdom works with Node.js, which does not support that syntax. So this issue doesn’t make sense.

If you are using some nonstandard tool to work with jsdom, you need to file this help request on them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with objects - JavaScript - MDN Web Docs - Mozilla
Define the object type by writing a constructor function. There is a strong convention, with good reason, to use a capital initial letter....
Read more >
How to conditionally build an object in JavaScript with ES6
The first is parameter object destructuring, which is a good pattern if you want to deal with lots of arguments in a function....
Read more >
Create instance of ES6 class from JSON result - Stack Overflow
What's the easiest way to create an instance of an ES6 class from a JSON object? E.g., given something like: class Foo constructor(bar) ......
Read more >
JavaScript ES6 - W3Schools
You don't need the function keyword, the return keyword, and the curly brackets. Example. // ES5 var x = function(x, y) {
Read more >
Working with JavaScript in Visual Studio Code
While IntelliSense should just work for most JavaScript projects without ... For example, on Windows, you would add a path like this to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found