rough icon indicating copy to clipboard operation
rough copied to clipboard

Use in Nextjs

Open kaisiant opened this issue 4 years ago • 5 comments

import rough from "roughjs/bundled/rough.esm" image

import rough from "roughjs/bin/rough" image

I need some help, thanks

kaisiant avatar Sep 14 '21 14:09 kaisiant

Seems like you are having trouble loading es6 modules in next. Not sure how to configure that. You can also try loading from roughjs/bundled/rough.cjs.js

pshihn avatar Nov 03 '21 06:11 pshihn

~~AFAIK it's resolved in Next 12.~~

ShahriarKh avatar Feb 08 '22 17:02 ShahriarKh

AFAIK it's resolved in Next 12.

Can you get it working? No luck here, even tried using next-transpile-modules.

williamsjokvist avatar Aug 15 '22 19:08 williamsjokvist

AFAIK it's resolved in Next 12.

Can you get it working? No luck here, even tried using next-transpile-modules.

was able to achieve rough-like effect in next using the thi.ng geom-fuzz library 🤷‍♂️

museumhotel avatar Oct 22 '22 16:10 museumhotel

Here is a simple example in Next:

import rough from "roughjs/bundled/rough.cjs.js";

export default function ComponentName() {
    useEffect(() => {
        let svg = document.getElementById('some-id');
        const rc = rough.svg(svg);
        let node = rc.circle(12, 12, 20);
        svg.appendChild(node);
    }, [])

    return <svg id='some-id' />
}

be sure to set height ad width for your <svg> element. I'm using useEffect here to ensure the element is created in client-side (not server-side) and document is available.

ShahriarKh avatar Nov 10 '22 12:11 ShahriarKh