我试图使用@react查看器/core@3.7.0实现PDF查看器,它依赖于pdfjs@2.15.349。我已经安装了这两个库,但是我得到了以下错误:
./node_modules/pdfjs-dist/build/pdf.js 1259:21
Module parse failed: Unexpected token (1259:21)
File was processed with these loaders:
* ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|
| class PixelsPerInch {
> static CSS = 96.0;
| static PDF = 72.0;
| static PDF_TO_CSS_UNITS = this.CSS / this.PDF;我尝试过删除和重新安装node_modules,但它根本没有工作。我没有巴贝尔装载机。我用的是"typescript": "^4.1.2","react": "^17.0.2"。我该如何解决这个问题?
发布于 2022-10-26 14:28:31
从错误中,我可以看出您使用的是react-scripts (这也是babel-loader的来源,无论它的价值是什么--您正在使用它,它是一个隐式依赖)。
我今天也遇到了同样的错误。在我的例子中,我试图将故事书添加到现有的react-scripts项目中。项目本身构建得很好,但是故事书的构建由于您的错误而崩溃了。
我最终发现添加这个webpack规则就足以让我的构建工作起来。它是react-scripts自己为外部包代码所做的精简版本(我是通过弹出和查看生成的文件找到的)。
{
test: /\/pdfjs-dist\//,
loader: require.resolve('babel-loader'),
options: {
presets: [
[
// Latest stable ECMAScript features
require('@babel/preset-env').default,
],
],
},
},希望这对你有帮助!
https://stackoverflow.com/questions/73447261
复制相似问题