ng2-pdf-viewer: Error: Module not found: Error: Can't resolve 'canvas' in 'path/to/node_modules/pdfjs-dist/es5/build'
Hi great library to work with, I am facing the following issue with the latest version of ng2-pdf-viewer which 7.0.1 while creating the build by using the command npm run build:ssr.
./node_modules/pdfjs-dist/es5/build/pdf.js:14174:21-38 - Error: Module not found: Error: Can't resolve 'canvas' in '/path/to/node_modules/pdfjs-dist/es5/build''
It was working fine with the previous version 6.4.1.
I am working with angular 11.
Any suggestion of even a place to look to achieve the desired results? Regards,
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 22
- Comments: 22
I finally found a solution! however it has been a long path. you can write me and I will help you directly! my email: guillermoalexandermoran@gmail.com
Same Problem for me
same problem for me
@predycsoft Kindly share the solution here. So everyone in the future can also take help from it. Thanks
Hi @cwooi95 I tried changing the angular.json file doing the following:
“server”: { “builder”: “@angular-devkit/build-angular:server”, “options”: { “outputPath”: “dist/CursosPredyc/server”, “main”: “server.ts”, “tsConfig”: “tsconfig.server.json”, “externalDependencies”: [ “canvas” ] },
And that makes the build:ssr run successfully, however, now I am facing a problem in the npm run prerender and the serve-ssr:
C:\Users\guill\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:114201 document.webL10n = function (window, document, undefined) { ^
ReferenceError: document is not defined at Array.Object.defineProperty.value (C:\Users\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:114201:1) at w_pdfjs_require (C:\Users\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:119494:41) at Array.<anonymous> (C:\User\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:114040:1) at w_pdfjs_require (C:\Users\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:119494:41) at Array.Object.defineProperty.value (C:\Users\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:111206:20) at w_pdfjs_require (C:\Users\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:119494:41) at C:\Users\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:119517:18 at C:\Users\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:119518:12 at webpackUniversalModuleDefinition (C:\Users\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:111085:20) at Object.BPYd (C:\Users\xx\xx\xx\xx\dist\CursosPredyc\server\main.js:111087:3)
A server error has occurred.
I hope this will help to advance forward this issue.