zeligzhou / xmldom-qsa

A pure JavaScript W3C standard-based (XML DOM Level 2 Core) `DOMParser` and `XMLSerializer` module.
MIT License
6 stars 1 forks source link

How to extend `Node` using ESM? #6

Open jsoldi opened 2 months ago

jsoldi commented 2 months ago

Hi ,I'm trying to do something similar to the example on the readme:

doc.documentElement.querySelector('.clazz');
var Node = require('xmldom-qsa/dom').Node;
Node.prototype.addAttr = function(x,y) { ... }
doc.documentElement.addAttr('x','y');

but I'm using ESM modules so I'm trying to import dom like import { Node } from "xmldom-qsa/dom"; or import Node from "xmldom-qsa/dom"; but no matter what I do typescript tells me "Cannot find module 'xmldom-qsa/dom' or its corresponding type declarations." so I wonder if there's any workaround to do this?

SgaBenza commented 1 day ago

@jsoldi they put the wrong path in the documentation. You can import the node element from here

var Node = require('xmldom-qsa/lib/dom').Node