1904labs / dom-to-image-more

Generates an image from a DOM node using HTML5 canvas

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node is not defined error

nstuyvesant opened this issue · comments

Use case: description, code

dom-to-image-more@3.1.4 is imported into a TypeScript project. Rollup is being used and we get this error...

bundling src...
[!] ReferenceError: Node is not defined
ReferenceError: Node is not defined
    at /Users/nates/dev/rebase/node_modules/dom-to-image-more/src/dom-to-image-more.js:8:26
    at Object.<anonymous> (/Users/nates/dev/rebase/node_modules/dom-to-image-more/src/dom-to-image-more.js:1395:3)
    at Module._compile (internal/modules/cjs/loader.js:1114:14)
    at Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
    at Object.require.extensions.<computed> [as .js] (/Users/nates/dev/rebase/node_modules/rollup/dist/bin/rollup:835:17)
    at Module.load (internal/modules/cjs/loader.js:979:32)
    at Function.Module._load (internal/modules/cjs/loader.js:819:12)
    at Module.require (internal/modules/cjs/loader.js:1003:19)
    at require (internal/modules/cjs/helpers.js:107:18)
    at Object.<anonymous> (/Users/nates/dev/rebase/packages/core/rollup.config.js:14:34)

This line...

    const ELEMENT_NODE = Node.ELEMENT_NODE || 1;

causes an error if Node is not defined.

This would solve this issue (will submit a PR)...

const ELEMENT_NODE = typeof Node === 'undefined' ? 1 : Node.ELEMENT_NODE || 1;

Expected behavior

Assignment would check to see if Node is defined before referencing a property.

Actual behavior (stack traces, console logs etc)

Assumes Node.ELEMENT_NODE will be undefined then default the value to 1.

Library version

3.1.4

Browsers

  • Chrome 112