paperjs / paper.js

The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey
http://paperjs.org
Other
14.5k stars 1.23k forks source link

ImportSVG does not work with NodeJS #1974

Open xesxen opened 2 years ago

xesxen commented 2 years ago

Description/Steps to reproduce

When adding an SVG using importSVG within NodeJS, the library throws an TypeError:

.../paper/node_modules/paper/dist/paper-full.js:15624
                throw new Error(message);
                      ^

Error: TypeError: Cannot read properties of undefined (reading 'getPropertyValue')
    at onError (.../paper/node_modules/paper/dist/paper-full.js:15624:11)
    at onLoad (.../paper/node_modules/paper/dist/paper-full.js:15615:5)
    at importSVG (.../paper/node_modules/paper/dist/paper-full.js:15650:4)
    at Project.importSVG (.../paper/node_modules/paper/dist/paper-full.js:15665:11)
    at file://.../paper/cli.mjs:7:15
    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:385:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)

Node.js v17.8.0

Link to reproduction test-case

https://github.com/xesxen/paper-bug

Expected result

The application exits without throwing an error

Additional information

I'm running NodeJS 17.8.0 on Linux along with paper.js 0.12.15

Changing https://github.com/paperjs/paper.js/blob/develop/src/dom/DomElement.js#L42 to return view && ''; makes it work, though obviously this is not the correct solution for this issue.

dtbaker commented 7 months ago

I'm getting slightly different error with the bare minimum example:

Error: TypeError: e.DOMParser is not a constructor