'pdfjs-dist' 中的模块解析错误 angular 中的模块

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

在 Angular

中尝试使用 'pdfjs-dist' npm 模块构建项目时出现以下错误
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
|       });
|     } 

如何解决? 任何解决方法或建议都会有很大帮助!

可以通过将 'pdfjs-dist' 模块版本从 2.7.570 降级到较低的稳定版本(例如 2.5.207)来修复此错误。

另一个修复可能是将 webpack 的版本从 4.x 升级到 5.x,但这不是推荐的解决方案,因为这可能会导致项目的其他依赖模块出现问题。

我遇到了同样的错误。这对我有用,可能对你也有用

------------使用这些行--------

"fileReplacements": [
       {
                "replace": "./node_modules/jspdf/dist/jspdf.es.min.js",
                "with": "./node_modules/jspdf/dist/jspdf.umd.min.js"
              }
],

在angular.json文件中,

"build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
place the above code here....
........
}