konvajs / react-konva

React + Canvas = Love. JavaScript library for drawing complex canvas graphics using React.
https://konvajs.github.io/docs/react/
MIT License
5.8k stars 260 forks source link

NextJS: Module not found: Can't resolve 'canvas' #785

Open developer-sushant opened 11 months ago

developer-sushant commented 11 months ago

I am trying to use react-konva in nextjs and getting an error:

./node_modules/konva/lib/index-node.js:4:15 Module not found: Can't resolve 'canvas' Did you mean './canvas'? Requests that should resolve in the current directory need to start with './'. Requests that start with a name are treated as module requests and resolve within module directories (node_modules). If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

https://nextjs.org/docs/messages/module-not-found

lavrton commented 11 months ago

Did you try this https://github.com/konvajs/react-konva?tab=readme-ov-file#usage-with-nextjs ?

FranciscoAnghinoni commented 6 months ago

Hey @developer-sushant, I'm guessing you're having trouble getting Canvas to work on your Mac. I had the same problem! You probably need to install Xcode and Homebrew first. I don't remember the exact steps, but I googled the error message on Google's AI website (ai.google.com) and found instructions. After using Homebrew to install some things, Canvas finally worked for me. Hope this helps!