1

When running my application with ng serve everything works fine. But after building it with ng build --prod I get ...

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 
'assets/pdfjs/web/viewer.html' 
Error: Cannot match any routes. URL Segment: 'assets/pdfjs/web/viewer.html'

... at the moment the pdfviewer component should be displayed. What am I doing wrong? Thanks for your help.

heinob
  • 19,127
  • 5
  • 41
  • 61
  • Heinob, I struggled with the same issue as you and ultimately gave up trying to get this particular PDF viewer to work in angular after making various attempts to add the static route. I found a different PDF viewer that works right out of the box which is very similar to this one and doesn't throw that error when deploying to production. Here's a link to that 3rd party module: https://www.npmjs.com/package/ngx-extended-pdf-viewer – Reed G Jan 12 '20 at 05:26

2 Answers2

4

Add below snippet to

"projects.your-project-name.architect.build.options.assets"

array in angular.json which is basically "assets"

{
    "glob": "**/*",
    "input": "./node_modules/ng2-pdfjs-viewer/pdfjs",
    "output": "/assets/pdfjs"
}

NOTE: It is /assets/pdfjs even though your assets is inside src folder.

It will automatically copy pdfjs folder in node_modules/ng2-pdfjs-viewer. It is better than manually copying the files because manually copying files may cause version inconsistency on package update.

Vishnudev Krishnadas
  • 10,679
  • 2
  • 23
  • 55
1

I met the same problem, but I solved it. Record my solution. I hope it will help.

  1. Find the ng2-pdfjs-viewer folder in the node_modules folder;
  2. Copy the pdfjs to the assets folder in the project
  3. Restart

My environment: angular5.2.10 + ionic5.4.13 + ng2-pdfjs-viewer (latest version as of March 12, 2020)

Vishnudev Krishnadas
  • 10,679
  • 2
  • 23
  • 55
shen wang
  • 11
  • 2