'Next.js: Module not found: Can't resolve 'canvg'

I have a next.js project and I keep getting:

error - ./node_modules/jspdf/dist/jspdf.es.min.js:458:25
Module not found: Can't resolve 'canvg'

I'm not sure why because I'm not including either jspdf or canvg.

Not sure what's causing it. Any help would be appreciated. I'm using material-ui if that matters.



Solution 1:[1]

It seems dependency error means that particular Module is missing when it's running.

Run npm ls or yarn list will print to stdout all the versions of packages that are installed, as well as their dependencies, in a tree-structure. Then search for that particulate packages are listed or not. Run npm ls jspdf or yarn list jspdf then you can see its list of dependencies in tree-structure.

Please check your node version is updated or not ? If not then update first.

Quick & Dirty way: delete package.lock or yarn.lock file and delete .node_modules folders And Then run npm install or yarn to install again. Look at console while you installing and make sure there are no error in the installing process. If you saw error you better look that massages also.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SHUVO MUSA