javascriptangularpdf

Module parse error in 'pdfjs-dist' module in angular


Following error is obtained when trying to build project using 'pdfjs-dist' npm module in Angular

Module parse failed: Unexpected token (2413:45)
File was processed with these loaders:
 * ./node_modules/@angular-devkit/build-angular/src/babel/webpack-loader.js
 * ./node_modules/@ngtools/webpack/src/ivy/index.js
You may need an additional loader to handle the result of these loaders.
|         intent: renderingIntent,
|         renderInteractiveForms: renderInteractiveForms === true,
>         annotationStorage: annotationStorage?.getAll() || null
|       });
|     } 

How to resolve this? Any workarounds or suggestions would help a lot!


Solution

  • This error can be fixed by downgrading the version of 'pdfjs-dist' module version from 2.7.570 to a lower stable version say 2.5.207.

    Another fix could be upgrading the version of webpack from 4.x to 5.x, but this is not a recommended solution as this can create issues with the other dependent modules of the project.