exceljs: workbook.xlsx.writeBuffer() silently breaks since v1.11.0, only in production

I have a hard time believing what is happening to me: After getting error complaints from users I found that exports are silently failing. Only in production. It works fine in dev mode!?

After some debugging I could narrow it down to the await workbook.xlsx.writeBuffer() line in this module of mine, as console.log nr. 5 is the last to appear in production:

import * as ExcelJs from 'exceljs/dist/exceljs.min.js'

import getDataArrayFromExportObjects from './getDataArrayFromExportObjects'

export default async ({ data, store }) => {
  console.log('getXlsxBuffer 1')
  const dataArray = getDataArrayFromExportObjects(data)
  console.log('getXlsxBuffer 2', { dataArray })
  const numberOfColumns =
    dataArray && dataArray[0] && dataArray[0].length ? dataArray[0].length : 0
  const workbook = new ExcelJs.Workbook()
  console.log('getXlsxBuffer 3', { workbook })
  const worksheet = workbook.addWorksheet('Daten', {
    views: [
      {
        state: 'frozen',
        xSplit: 0,
        ySplit: 1,
      },
    ],
    autoFilter: {
      from: {
        row: 1,
        column: 1,
      },
      to: {
        row: 1,
        column: numberOfColumns,
      },
    },
  })
  worksheet.addRows(dataArray)
  worksheet.getRow(1).fill = {
    type: 'gradient',
    gradient: 'angle',
    degree: 0,
    stops: [
      { position: 0, color: { argb: 'FFD3D3D3' } },
      { position: 1, color: { argb: 'FFD3D3D3' } },
    ],
  }
  worksheet.getRow(1).font = {
    bold: true,
  }
  worksheet.getRow(1).border = {
    bottom: {
      style: 'thin',
    },
  }
  console.log('getXlsxBuffer 4')
  let buffer
  try {
    console.log('getXlsxBuffer 5')
    buffer = await workbook.xlsx.writeBuffer()
    console.log('getXlsxBuffer 6')
  } catch (error) {
    console.log('getXlsxBuffer, error:', error)
    return store.enqueNotification({
      message: error.message,
      options: {
        variant: 'error',
      },
    })
  }
  console.log('getXlsxBuffer 7', { buffer })
  return buffer
}

I then started rolling back versions and found that it works fine in v1.10.0 in production.

Some more info:

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 10
  • Comments: 33 (1 by maintainers)

Most upvoted comments

I’m also having this problem with this library in Angular+CLI (8.2.0-next.0 atm). I tried switching to 1.10.0, but I have the same problem.

I think it’s a combination of Angular CLI’s build process being broken and some quirk with this library. Like the Promise library used by ExcelJS has been replaced by some kind of empty placeholder function.

Is there anything I can do to research this more on my own? I’d also like to help get ExcelJS into a more modern module, one that can be tree-shaken by webpack.

Edit: Nevermind, colleague had checked-in a bad package.json, was using 1.13.0 instead.

@Galeups The closed issue is the one stating that exports did not work in our project. Rolling back exceljs solved that.

The issue with exceljs remains, so this issue should remain open until the issue is resolved.

Hi not working in production ! V1.10 Angular 6 😦

I solved this issue here ->> https://stackoverflow.com/questions/56996774/exceljs-not-working-in-production-in-angular-6

I had the same issue on some browsers with version 1.12.0. Adding polyfill for Number.isNaN fixed this issue for me. import 'core-js/features/number/is-nan';

By comparing version 1.10 and 1.12, it seems that global isNaN was replaced with Number.isNaN for some reason. https://github.com/exceljs/exceljs/blob/v1.12.0/lib/csv/csv.js#L71 https://github.com/exceljs/exceljs/blob/v1.10.0/lib/csv/csv.js#L73

please solve this issue: I managed to update this dependency (as there is no good way to mark a dependency to not be updated in a package.json file), testing it in dev (works!) and getting error messages from users again 😦

when i use ng build --prod --base-href /dc/ build my project,this problem occurs,And i use ng build --aot --base-href /dc/ build my project, it works good.

Still having the same problem with version 1.13.0 – downgrading to 1.10.0 solved the issue. Thank you @barbalex !