taoqf / node-html-parser

A very fast HTML parser, generating a simplified DOM, with basic element query support.
MIT License
1.12k stars 112 forks source link

node-html-parser v1.4.2: Object prototype may only be an Object or null #81

Closed clementgalidie closed 3 years ago

clementgalidie commented 4 years ago

Hello!

Since the v1.4.2, I encounter this error: Object prototype may only be an Object or null: undefined Here is a screenshot of the stack trace: image To be more precise, the following code block generates the error:

var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };

b seems to have undefined as a value.

The project I'm working on runs with Nuxt.js v2.14.7 and Vue.js v2.6.12.

node-html-parser is used in this JavaScript file:

import { parse } from 'node-html-parser';

export default ({app}, inject) => {
  inject('getLazyLoadStream', (options) => {
    const tr = parse(options, {
      lowerCaseTagName: false,
      script: true,
      pre: true,
      comment: false
    })

    for (const img of tr.querySelectorAll('img')) {
      img.setAttribute('data-src', img.getAttribute('src'))
      img.setAttribute('data-sizes', 'auto')
      img.removeAttribute('src')
      img.setAttribute('class', ((img.getAttribute('class') || '') + ' lazyload').trimStart())
    }

    return tr.toString()
  })

  inject('lazyConverter', (data) => {
    return app.$getLazyLoadStream(data)
  })
}

I thought the following error was due to some invalid HTML so I tried to get 0 HTML error but that didn't solve the issue.

Before upgrading, I was using the v1.3.1 of node-html-parser and everything worked well. Do you've ideas about what's happening? :thinking:

skennel2 commented 4 years ago

Same here

younguna commented 4 years ago

same here. went down to 1.3.1 to work again.

taoqf commented 4 years ago

Sorry for that. will 1.4.3 work?

clementgalidie commented 4 years ago

Hello!

Sorry for the late answer @taoqf!

Thanks for your latest update! Currently, it works well with node v14.0.0 and npm v6.14.4.

We did a Node.js version downgrade due to several errors with node v.15

taoqf commented 4 years ago

@clementgalidie I am using v15.0.1. What's the errors?

taoqf commented 3 years ago

closing as no response.