node
node copied to clipboard
[Bug] Cannot load SVG using `Assets.load`
Reproduction:
npm i @pixi/node
echo '<?xml version="1.0" encoding="UTF-8"?><svg xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" width="32" height="32"></svg>' > test.svg
node -e "require('@pixi/node').Assets.load('test.svg');"
/home/ulysses/temp/pixi-node-test/node_modules/@pixi/assets/lib/loader/Loader.js:93
throw new Error(`[Loader.load] Failed to load ${url}.
^
Error: [Loader.load] Failed to load /home/ulysses/temp/pixi-node-test/test.svg.
ReferenceError: Image is not defined
at /home/ulysses/temp/pixi-node-test/node_modules/@pixi/assets/lib/loader/Loader.js:93:17
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.all (index 0)
at async Loader.load (/home/ulysses/temp/pixi-node-test/node_modules/@pixi/assets/lib/loader/Loader.js:98:5)
at async AssetsClass._mapLoadToResolve (/home/ulysses/temp/pixi-node-test/node_modules/@pixi/assets/lib/Assets.js:170:26)
at async AssetsClass.load (/home/ulysses/temp/pixi-node-test/node_modules/@pixi/assets/lib/Assets.js:95:17)
Node.js v18.16.0
The cause of the bug is here:
https://github.com/pixijs/pixijs/blob/9ce9bd2c80837265b986e1fa7af37a3d9fb4393d/packages/core/src/textures/resources/SVGResource.ts#L110
The new Image() is causing the ReferenceError because there is no Image in the Node environment.