exceljs: [BUG] Angular 9 support?

🐛 Bug Report

After updating my angular application to v9, I’m getting the following errors:

ERROR in node_modules/exceljs/index.d.ts:1284:22 - error TS2307: Cannot find module 'stream'.

1284  read(stream: import('stream').Stream): Promise<Workbook>;
                          ~~~~~~~~
node_modules/exceljs/index.d.ts:1310:23 - error TS2307: Cannot find module 'stream'.

1310  write(stream: import('stream').Stream, options?: Partial<XlsxWriteOptions>): Promise<void>;
                           ~~~~~~~~
node_modules/exceljs/index.d.ts:1332:22 - error TS2307: Cannot find module 'stream'.

1332  read(stream: import('stream').Stream, options?: Partial<CsvReadOptions>): Promise<Worksheet>;
                          ~~~~~~~~
node_modules/exceljs/index.d.ts:1352:23 - error TS2307: Cannot find module 'stream'.

1352  write(stream: import('stream').Stream, options?: Partial<CsvWriteOptions>): Promise<void>;
                           ~~~~~~~~
node_modules/exceljs/index.d.ts:1649:19 - error TS2307: Cannot find module 'stream'.

1649            stream: import('stream').Stream;

Lib version: X.Y.Z

Steps To Reproduce

  1. Just update the angular application to version 9.

My current application dependencies:


  "dependencies": {
    "@angular/animations": "^9.0.4",
    "@angular/cdk": "^9.1.0",
    "@angular/common": "^9.0.4",
    "@angular/compiler": "^9.0.4",
    "@angular/core": "^9.0.4",
    "@angular/forms": "^9.0.4",
    "@angular/http": "^7.2.16",
    "@angular/material": "^9.1.0",
    "@angular/platform-browser": "^9.0.4",
    "@angular/platform-browser-dynamic": "^9.0.4",
    "@angular/router": "^9.0.4",
    "@asymmetrik/angular2-leaflet": "^2.2.1",
    "@auth0/angular-jwt": "^4.0.0",
    "@ngx-lite/input-switch": "^0.3.3",
    "@types/geojson": "^7946.0.7",
    "@types/leaflet": "^1.5.9",
    "ag-grid-angular": "^22.1.1",
    "ag-grid-community": "^22.1.1",
    "angular2-jwt": "0.2.3",
    "angular2-multiselect-dropdown": "^4.6.3",
    "bootstrap": "^4.4.1",
    "chart.js": "^2.9.3",
    "chartjs-plugin-annotation": "^0.5.7",
    "chartjs-plugin-labels": "^1.1.0",
    "chartjs-plugin-title-click": "^1.0.0",
    "core-js": "^3.6.4",
    "exceljs": "^3.8.0",
    "file-saver": "^2.0.2",
    "jquery": "^3.4.1",
    "leaflet": "^1.3.4",
    "leaflet-extra-markers": "^1.2.1",
    "ng2-charts": "^2.3.0",
    "ng2-sticky-nav": "^6.1.0",
    "ngx-bootstrap": "^5.3.2",
    "ngx-mat-select-search": "^2.1.1",
    "ngx-pagination": "^5.0.0",
    "ngx-toggle-switch": "^2.0.5",
    "node-sass": "^4.13.1",
    "rxjs": "^6.5.4",
    "xlsx": "^0.15.5",
    "zone.js": "^0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.900.4",
    "@angular/cli": "^9.0.4",
    "@angular/compiler-cli": "^9.0.4",
    "@angular/language-service": "^9.0.4",
    "@types/jasmine": "^3.5.7",
    "@types/jasminewd2": "^2.0.8",
    "@types/node": "^13.7.6",
    "codelyzer": "^5.2.1",
    "jasmine-core": "^3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.4.1",
    "karma-chrome-launcher": "^3.1.0",
    "karma-coverage-istanbul-reporter": "^2.1.1",
    "karma-jasmine": "^3.1.1",
    "karma-jasmine-html-reporter": "^1.5.2",
    "protractor": "^5.4.3",
    "ts-node": "^8.6.2",
    "tslint": "^6.0.0",
    "typescript": "~3.7.5"
  }

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 3
  • Comments: 15

Most upvoted comments

“types”: [“node”]. Add this to tsconfig.app.json file. Worked for me.

I added paths in tsconfig.app.json

{
  "compileOnSave": false,
  "compilerOptions": {
  ...
    "paths": {
      "exceljs": [
        "node_modules/exceljs/dist/exceljs.js"
      ]
    }
  },
  "angularCompilerOptions": {
    "fullTemplateTypeCheck": true,
    "strictInjectionParameters": true
  }
}

“types”: [“node”], funciona, hay que agregar en el archivo tsconfig.app.json

“types”: [“node”]. Add this to tsconfig.app.json file. Worked for me.

this has worked for me.

angular.json

include the following line in script block. “./node_modules/exceljs/dist/exceljs.min.js”

"architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist/logistica-oriental-ui",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "tsconfig.app.json",
            "aot": true,
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "./node_modules/@angular/material/prebuilt-themes/indigo-pink.css",
              "src/styles.scss"
            ],
            "scripts": [
              "./node_modules/exceljs/dist/exceljs.min.js"
            ]
          }...

package.json

include exceljs and file-saver dependency

 "dependencies": {
    "@angular/animations": "~9.0.2",
    "@angular/cdk": "^9.2.4",
    "@angular/common": "~9.0.2",
    "@angular/compiler": "~9.0.2",
    "@angular/core": "~9.0.2",
    "@angular/forms": "~9.0.2",
    "@angular/material": "^9.2.4",
    "@angular/platform-browser": "~9.0.2",
    "@angular/platform-browser-dynamic": "~9.0.2",
    "@angular/router": "~9.0.2",
    "@fortawesome/angular-fontawesome": "^0.6.1",
    "@fortawesome/fontawesome-svg-core": "^1.2.28",
    "@fortawesome/free-solid-svg-icons": "^5.13.0",
    "dayjs": "^1.8.33",
    "exceljs": "^1.12.0",
    "file-saver": "^2.0.2",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
"devDependencies": {
    "@angular-devkit/build-angular": "^0.1000.5",
    "@angular/cli": "~9.0.3",
    "@angular/compiler-cli": "~9.0.2",
    "@angular/language-service": "~9.0.2",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^5.2.2",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "^7.0.0",
    "ts-node": "~8.3.0",
    "tslint": "~5.18.0",
    "typescript": "~3.7.5"
  }

export-excel.service.ts

import the dependencies in the component or service to use.

  • declare const ExcelJS: any;
  • import * as fs from ‘file-saver’;
import { Injectable } from '@angular/core';

declare const ExcelJS: any;
import * as fs from 'file-saver';

@Injectable({
  providedIn: 'root'
})
export class ExportExcelService {

  constructor() { }

  generateExcel(title: string, headers: string[], data: any) { 
    const workbook = new ExcelJS.Workbook();
    ...
  }

“paths”: { “exceljs”: [ “node_modules/exceljs/dist/exceljs.js” ] }

I’m using now Angular 11.xx.x and using this configuration doesn’t work for me, but I modify it like this, and now it’s working


{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "paths": {
      "exceljs": [
        "node_modules/exceljs/dist"
      ]
    }
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
   #]
}

“types”: [“node”]. Add this to tsconfig.app.json file. Worked for me.