Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when exporting to SVG on node 18 #2037

Open
KarelJanVanHaute opened this issue Jun 14, 2023 · 3 comments
Open

Error when exporting to SVG on node 18 #2037

KarelJanVanHaute opened this issue Jun 14, 2023 · 3 comments

Comments

@KarelJanVanHaute
Copy link

KarelJanVanHaute commented Jun 14, 2023

I'm using paper-jsdom-canvas to render a paperjs and then export it to an .svg. On the export I get the following error.

error - TypeError: Cannot read properties of undefined (reading 'createElementNS')

It used to work on node 14. But I need to upgrade to at least node 18.
The error is thrown at line 14652 in paper-full.js
There is this code:

function create(tag, attributes, formatter) {
	return set(document.createElementNS(svg, tag), attributes, formatter);
}

So document seems to be undefined.
When I update jsdom to the latest version , that part seems to work, but then we get the following Error

Error: Not implemented: HTMLCanvasElement.prototype.getContext (without installing the canvas npm package)

But the canvas package is installed. Also to the latest version.

Expected result

To export to .svg

Additional information

macOS 13.4, Node v20.3.0

@samubence
Copy link

I have the same problem, i've posted here: #634 (comment)

@rfried
Copy link

rfried commented Nov 1, 2023

I am seeing this issue as well. I had to upgrade to node 18 because AWS has officially deprecated Node 16 and now I can't create SVGs on my server.
Here's a simple reproduction using Node 18: https://stackblitz.com/edit/nuxt-starter-ibtaly

@Delwing
Copy link

Delwing commented Dec 8, 2023

I run into same issue, yet I was able to actually run it correctly on Node 18 & Node 20.

After digging down, reason for not working is buried inside:
https://github.com/paperjs/paper.js/blob/develop/src/node/self.js:28

try {
    jsdom = require('jsdom');
} catch(e) {
    // Check the required module's name to see if it contains jsdom, and only
    // complain about its lack if the module requires it.
    if (/\bjsdom\b/.test(requireName)) {
        throw new Error('Unable to load jsdom module.');
    }
}

jsdom is undefined, since there is some issue when trying to require jsdom and then tough-cookie.

Issues persisted for me on Windows, when I used WSL to run my app it worked perfectly fine. So I started further experiments. What actually helped me on Windows was removing nvm and installing it again.

@KarelJanVanHaute @rfried @samubence if you might share whether this was the case for you, if so, maybe there is some issue with nvm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants