reactjs 尝试将react-pdf与 typescript 一起使用

iugsix8n  于 2023-02-12  发布在  React
关注(0)|答案(1)|浏览(245)

我有一个使用craco构建的React应用程序,我想添加react-pdf以在react组件中显示PDF文件。
我收到以下错误:

我已经将以下内容添加到craco.config.js文件中,该文件显然替换了webpack.config

module.exports = {
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            modifyVars: { '@primary-color': '#1c48f2' },
            modules: true,
            javascriptEnabled: true
          }
        },
      }
    },
    { plugin: CracoTerserOverridePlugin }
  ],
  webpack: {
    options: {
      presets: [
        "@babel/preset-env",
        "@babel/preset-react"
      ],
      plugins: [
          [
            "@babel/plugin-proposal-class-properties",
            "@babel/plugin-syntax-class-properties"
          ]
      ],
    },
    plugins: process.env.NODE_ENV === 'production' ? [
      ...
    }),
  ] : [],
  }
};

tsconfig.json

{
  "compilerOptions": {
    "baseUrl": "src",
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

我试过在此对象中添加位置,但似乎无法修复它。我假设需要添加其他内容。

m0rkklqb

m0rkklqb1#

您的目标是“es5”,但您使用的模块使用“ES6”属性。privateClassProperties仅可从“ES6”获得
你有没有可能瞄准“ES6”?
很难分辨它是在tsc蒸发阶段还是巴别塔阶段。
如果它是在babel阶段,你将需要一个.babelrc文件,你可能需要一个.babelrc指定目标浏览器版本,如果它不工作在tsconfig.json

"presets": [
    ["babel-preset-env", {
        "targets": {
            "browsers": "last 2 versions"
        },
    }]
 ]

相关问题