Reactjs 未能编译模块解析失败:导入或访问docx文件时出现意外字符

Reactjs 未能编译模块解析失败:导入或访问docx文件时出现意外字符,reactjs,pdf,react-router,docx,Reactjs,Pdf,React Router,Docx,我想要一个按钮谁是要下载一个docx文件点击,该文件是静态的,并在图像/下载目录中有以下我已经尝试,并没有运气 首先,试试- <a href={require("../../images/downloads/Gate-Pass-Moving-in.docx")} className="btn btn-sm btn-secondary" download > Download </a> --然后在按钮中-- 我在接下来的两次尝试中都遇到了

我想要一个按钮谁是要下载一个docx文件点击,该文件是静态的,并在图像/下载目录中有以下我已经尝试,并没有运气

首先,试试-

 <a href={require("../../images/downloads/Gate-Pass-Moving-in.docx")}
    className="btn btn-sm btn-secondary"
    download >
     Download
 </a>
--然后在按钮中--


我在接下来的两次尝试中都遇到了相同的错误。 注意-我正在使用next和react


您可以使用文件的绝对路径

<a href="../../images/downloads/Gate-Pass-Moving-in.docx"
    className="btn btn-sm btn-secondary"
    download >
     Download
 </a>

您不能将.docx文件导入到您的Reactjs代码中,难道js文件或jsx文件不是第一次尝试时要导入的吗 但是你可以设置链接 或者您可以使用此软件包

    // @demobox
function makeFile() {
  // do some calculations
  return {
    mime: 'text/plain',
    filename: '../../images/downloads/Gate-Pass-Moving-in.docx',
    contents: 'all of the exports',
  }
}


<DownloadButton
  // these classes come from materializecss
  className='waves-effect waves-light btn' 
  genFile={makeFile}/> 

数据参数中会有什么?在使用js文件下载包时,您可以分享错误吗?对于DownloadButton软件包,我已经分享了描述中错误的屏幕截图。我没有用过这个,我有一个问题,请看我以前的评论,这项工作,但当我使捆绑包再次停止工作时
<a href="../../images/downloads/Gate-Pass-Moving-in.docx"
    className="btn btn-sm btn-secondary"
    download >
     Download
 </a>
    // @demobox
function makeFile() {
  // do some calculations
  return {
    mime: 'text/plain',
    filename: '../../images/downloads/Gate-Pass-Moving-in.docx',
    contents: 'all of the exports',
  }
}


<DownloadButton
  // these classes come from materializecss
  className='waves-effect waves-light btn' 
  genFile={makeFile}/> 
var fileDownload = require('js-file-download');
fileDownload(data, '../../images/downloads/Gate-Pass-Moving-in.docx');