安装Yapi-plugin-export-docx-data后无法使用YApi

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

Uncaught SyntaxError: Identifier 'Buffer' has already been declared

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

Module parse failed: C:WORKSPACEPublishSitemy-yapivendors
ode_modulesswagger-clientlib
esolver.js Unexpected token (123:38)
You may need an appropriate loader to handle this file type.
Module parse failed: C:WORKSPACEPublishSitemy-yapivendors
ode_modulesufferindex.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需要有模板。

原文地址:https://www.cnblogs.com/WattWang/p/yapi-plugin-export-docx-data.html