添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

react-boilerplate Error: Can't resolve '../xlsx' in '/Users/react-boilerplate/node_modules/xlsx-style'

Ask Question Time: 3566ms Built at: 08/05/2018 6:10:17 PM Asset Size Chunks Chunk Names reactBoilerplateDeps.dll.js 4.81 MiB reactBoilerplateDeps [emitted] [big] reactBoilerplateDeps chunk {reactBoilerplateDeps} reactBoilerplateDeps.dll.js (reactBoilerplateDeps) 4.15 MiB [entry] [rendered] WARNING in ./node_modules/xlsx-style/ods.js Module not found: Error: Can't resolve '../xlsx' in '/Users/mehrnooshhajkhalil/react-boilerplate/node_modules/xlsx-style' @ ./node_modules/xlsx-style/ods.js @ ./node_modules/xlsx-style/xlsx.js @ ./node_modules/node-excel-export/lib/excel.js @ ./node_modules/node-excel-export/index.js @ dll reactBoilerplateDeps ERROR in ./node_modules/xlsx-style/dist/cpexcel.js Module not found: Error: Can't resolve './cptable' in '/Users/mehrnooshhajkhalil/react-boilerplate/node_modules/xlsx-style/dist' @ ./node_modules/xlsx-style/dist/cpexcel.js 807:16-41 @ ./node_modules/xlsx-style/xlsx.js @ ./node_modules/node-excel-export/lib/excel.js @ ./node_modules/node-excel-export/index.js @ dll reactBoilerplateDeps ERROR in ./node_modules/xlsx-style/xlsx.js Module not found: Error: Can't resolve 'fs' in '/Users/mehrnooshhajkhalil/react-boilerplate/node_modules/xlsx-style' @ ./node_modules/xlsx-style/xlsx.js 1204:27-40 1340:8-24 @ ./node_modules/node-excel-export/lib/excel.js @ ./node_modules/node-excel-export/index.js @ dll reactBoilerplateDeps ERROR in ./node_modules/xlsx-style/ods.js Module not found: Error: Can't resolve 'fs' in '/Users/mehrnooshhajkhalil/react-boilerplate/node_modules/xlsx-style' @ ./node_modules/xlsx-style/ods.js 58:8-24 @ ./node_modules/xlsx-style/xlsx.js @ ./node_modules/node-excel-export/lib/excel.js @ ./node_modules/node-excel-export/index.js @ dll reactBoilerplateDeps ERROR in ./node_modules/xlsx-style/ods.js Module not found: Error: Can't resolve 'xlsx' in '/Users/mehrnooshhajkhalil/react-boilerplate/node_modules/xlsx-style' @ ./node_modules/xlsx-style/ods.js 13:21-41 @ ./node_modules/xlsx-style/xlsx.js @ ./node_modules/node-excel-export/lib/excel.js @ ./node_modules/node-excel-export/index.js @ dll reactBoilerplateDeps removed 1 package and audited 53190 packages in 30.134s I am using react-boilerplate github.com/react-boilerplate/react-boilerplate after clone the project I do just npm install and this errors comes up. Mehrnoosh Aug 5, 2018 at 15:37

I was stuck in this issue like 1 week, The problem is when you want to use any package that are using export excel, they are using fs is short for file system. A browser doesn't have any.

Therefore, it is almost impossible export an excel file from reactboilerplate in front end, I did handle it by using node-excel-export then write an API for that like this:

export const exportIssues = (req, res) => {
  const styles = {
    headerDark: {
      fill: {
        fgColor: {
          rgb: 'FF000000'
      font: {
        color: {
          rgb: 'FFFFFFFF'
        sz: 14,
        bold: true,
        underline: true
//Here you specify the export structure
  const issueSpecification = {
    HousingManager: { // <- the key should match the actual data key
      displayName: 'Housing manager', // <- Here you specify the column header
      headerStyle: styles.headerDark, // <- Header style
      width: 120 // <- width in pixels
    CompanyName: { // <- the key should match the actual data key
      displayName: 'Company name', // <- Here you specify the column header
      headerStyle: styles.headerDark, // <- Header style
      width: 120 // <- width in pixels
    HousingManagerEmail: { // <- the key should match the actual data key
      displayName: 'Housing manager email', // <- Here you specify the column header
      headerStyle: styles.headerDark, // <- Header style
      width: 120 // <- width in pixels
  const issueData = [
    {HousingManager:'sss', CompanyName: 'xxx' , 	HousingManagerEmail:'xx@x.com'},
    {HousingManager:'sss', CompanyName: 'xxx' , 	HousingManagerEmail:'xx@x.com'},      
  const report = excel.buildExport(
    [ // <- Notice that this is an array. Pass multiple sheets to create multi sheet report
        name: 'Issues', // <- Specify sheet name (optional)
        specification: issueSpecification, // <- Report specification
        data: issueData // <-- Report data
// You can then return this straight
  res.set("Content-Disposition", "attachment;filename=report.xlsx");
  res.set("Content-type", "application/vnd.ms-excel")
  res.attachment('report.xlsx'); // This is sails.js specific (in general you need to set headers)
  return res.send(report);
    .then((response) => {
      download(response.data, "Issues.xlsx", "application/vnd.ms-excel");

Please replace the following code in ods.js

if(typeof XLSX !== 'undefined') return XLSX.utils;
if(typeof module !== "undefined" && typeof require !== 'undefined') 
    return require('./' + 'xlsx').utils; 
catch(e) 
         return require('./' + 'xlsx').utils; 
    catch(ee) 
        return require('./xlsx').utils; 
 throw new Error("Cannot find XLSX utils"); 
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.