13

我的反应应用程序中有pdfjs-dist依赖项,但它不工作 - 我不确定我改变了什么导致这种情况。我正在跑步node v14.16.1, npm v7.9.0, react 17.0.2, react-scripts 4.0.3, 和pdfjs-dist 2.7.570. 我在运行时收到以下错误消息npm start

Failed to compile.

./node_modules/pdfjs-dist/build/pdf.js 2407:53
Module parse failed: Unexpected token (2407:53)
File was processed with these loaders:
 * ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|                 intent: renderingIntent,
|                 renderInteractiveForms: renderInteractiveForms === true,
>                 annotationStorage: annotationStorage?.getAll() || null
|               });
|             }

我已经尝试卸载并重新安装相关软件包,以及npm update,npm audit等等。我也尝试添加worker-loadernpm 包,但它已经是对 pdfjs-dist 的对等依赖,所以它没有任何区别。我在这个项目上的合作伙伴有相同的回购,他没有任何问题,所以我确信这是我的目标。我相信这与对可选链接的支持有关,但不确定如何进行。谢谢!

4

3 回答 3

9

我只是偶然发现了同样的问题。我所做的是恢复pdfjs-dist到早期版本(在我的例子中是 2.9.359 回到 2.6.347)。现在一切正常,希望对某人有所帮助。

在另一个问题中可以找到类似案例的可能解释。

于 2021-08-05T07:39:04.750 回答
0

尝试将包包含在 babel-loader 规则中

  {
    test: /\.[tj]sx?$/i,
    include: [
      /\/node_modules\/pdfjs-dist/,`enter code here`
      /\/src/,
    ],
    loader: 'babel-loader',`enter code here`
    options: {},
  },
于 2021-10-07T10:21:29.097 回答
0

很可能您的 webpack 版本不正确。尝试使用 es5 构建 https://github.com/mozilla/pdf.js/issues/12905

于 2021-04-20T08:44:47.510 回答