Error when integrate SheetJS on Angular 4 + SystemJS (angular-seed)

133 Views Asked by At

I'm using this seed project with Angular 4 and SystemJS (angular-seed)

And want to use SheetJS to export Excel file. I follow the instruction, can import xlsx fine, but when export file it constantly return error:

XLSX.utils.aoa_to_sheet is not a function

I have added to the project.config.ts

 ...
 {
    name: 'xlsx',
    // Path to the package's bundle
    path: 'node_modules/xlsx/dist',
    packageMeta: {
      defaultExtension: 'js',
      main: 'xlsx.core.min.js'
    }
  }

And even modify the seed.config.ts

meta: {
    'xlsx': {
        exports: 'XLSX' // <-- this is needed to tell SystemJS to expose XLSX
    }
},
map: {
    'fs': '',     // <--|
    'crypto': '', // <--| suppress native node modules
    'stream': '', // <--|
},

But still cannot make the SystemJS understand to import XLSX correctly.

Anyone has faced this problem before can suggest me how to fix it. Any help is appreciated. Thank you.

1

There are 1 best solutions below

0
alex On

I just had this issue (but in a react app) the “xlsx.core.min.js” won’t really work

I never used angular but I imagine a config like this could work

{
    name: 'xlsx',
    // Path to the package's bundle
    path: 'node_modules/xlsx',
    packageMeta: {
        defaultExtension: 'js',
        main: 'xlsx.js'
    }
}

Also i would suggest to use “code splitting”, if available to your project, because this is a huge dependency