最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Next.js: Module not found: Can't resolve 'canvg' - Stack Overflow

programmeradmin3浏览0评论

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.

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.

Share Improve this question asked Oct 23, 2020 at 12:34 ShamoonShamoon 43.7k101 gold badges332 silver badges628 bronze badges 2
  • If you do npm ls jspdf that should help you determine what has it as a dependency. – Jacob Commented Oct 29, 2020 at 0:17
  • 4 @shamoon could you share your package.config file? – Dipen Shah Commented Oct 29, 2020 at 1:03
Add a ment  | 

2 Answers 2

Reset to default 4

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.

In my case, I was using react-pdf, which supposedly has canvg as an optional dependency (it or one of its dependencies) even though it was apparently required during a yarn build.

At first, I installed my dependencies using yarn install --frozen-lockfile --ignore-optional in a pipeline and I got that error.

I simply removed the --ignore-optional flag and now my install script is working.

发布评论

评论列表(0)

  1. 暂无评论