我正在尝试在我的 Angular 应用程序中将 pdfjs 模块更新到下一个版本(2.8.335)并收到以下错误:
ERROR in C:/project/node_modules/pdfjs-dist/build/pdf.js 2205:45
Module parse failed: Unexpected token (2205:45)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| intent: renderingIntent,
| renderInteractiveForms: renderInteractiveForms === true,
> annotationStorage: annotationStorage?.serializable || null
| });
| }
ERROR in C:/project/node_modules/pdfjs-dist/web/pdf_viewer.js 613:31
Module parse failed: Unexpected token (613:31)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| _cachedPageNumber(pageRef) {
| const refStr = pageRef.gen === 0 ? `${pageRef.num}R` : `${pageRef.num}R${pageRef.gen}`;
> return this._pagesRefCache?.[refStr] || null;
| }
这个问题与@angular-devkit/build-angular@0.901.15 使用的webpack 版本有关,我使用了适用于Angular 9 的最新版本。这个版本的build-angular 使用了触发这些错误的webpack@4.42.0。我发现在高于 5 版本的 webpack 中支持可选链接和空合并,但我受限于 Angular 9,无法将其更新到更高版本以加载 build-angular 和作为依赖项,webpack 到更高版本。
有没有办法配置 webpack 以支持 js 的可选链接和空合并功能,以便将模块加载到我的应用程序中?