安装完Yapi-plugin-export-docx-data后网页打开空白,F12打开Console报如下错误

Uncaught SyntaxError: Identifier 'Buffer' has already been declared

安装Yapi-plugin-export-docx-data时编译客户端报如下错误

Module parse failed: C:\WORKSPACE\PublishSite\my-yapi\vendors\node_modules\swagger-client\lib\resolver.js Unexpected token (123:38)
You may need an appropriate loader to handle this file type.
Module parse failed: C:\WORKSPACE\PublishSite\my-yapi\vendors\node_modules\buffer\index.js Unexpected token (1216:24)
You may need an appropriate loader to handle this file type.

 

根据issue二次开发运行或打包报swagger-client/lib/http.js等Module parse failed错误 · Issue #1865 · YMFE/yapi (github.com)

在yapi.config.js文件中添加如下代码,注意报Module parse failed错误的几个路径,我这边是node_modules/swagger-client和node_modules/buffer所以要对这两个路径进行设置。

     baseConfig.module.preLoaders.push({
          test: /\.(js|jsx)$/,
          include: [path.resolve(__dirname, './node_modules/swagger-client')],
          loader: 'babel-loader'
        });

     baseConfig.module.preLoaders.push({
          test: /\.(js|jsx)$/,
          include: [path.resolve(__dirname, './node_modules/buffer')],
          loader: 'babel-loader'
        });
 

重新安装后可以正常打开页面,导出docx

注意,导出word需要有模板。

 

相关文章:

  • 2021-11-10
  • 2021-04-07
  • 2021-06-28
  • 2021-11-19
  • 2021-07-29
  • 2021-06-30
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-24
  • 2021-07-29
  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案