13

If i run this code, i get an error, Cannot find namespace 'NodeJS'.

  public exportExcel(jsonData: any[], excelFileName: string): void {
    //Excel Title, Header, Data
    const header: string[] =  Object.keys(jsonData[0]);
    const data = jsonData;

    //Create workbook and worksheet
    let workbook = new Workbook();
    let worksheet = workbook.addWorksheet(excelFileName);

    //Add Header Row
    let headerRow = worksheet.addRow(header);

    // Cell Style : Fill and Border
    headerRow.eachCell((cell, number) => {
      cell.fill = {
        type: 'pattern',
        pattern: 'solid',
        fgColor: { argb: 'FFFFFF00' },
        bgColor: { argb: 'FF0000FF' }
      }
      cell.border = { top: { style: 'thin' }, left: { style: 'thin' }, bottom: { style: 'thin' }, right: { style: 'thin' } }
    })
    // Add Data and Conditional Formatting
    data.forEach((element) => {
      let eachRow = [];
      header.forEach((headers) => {
        eachRow.push(element[headers])
      })
      if (element.isDeleted === "Y") {
        let deletedRow = worksheet.addRow(eachRow);
        deletedRow.eachCell((cell, number) => {
          cell.font = { name: 'Calibri', family: 4, size: 11, bold: false, strike: true };
        })
      } else {
        worksheet.addRow(eachRow);
      }
    })

...

ERROR in node_modules/exceljs/index.d.ts(1648,34): error TS2503: Cannot find namespace 'NodeJS'.

8
  • github.com/exceljs/exceljs/issues/971 can help Commented Oct 3, 2019 at 17:16
  • ok thank you i will try Commented Oct 3, 2019 at 17:18
  • @dev but i get this information, what it´s mean? 100 unchanged chunks chunk {main} main.js, main.js.map (main) 429 kB [initial] [rendered] chunk {vendor} vendor.js, vendor.js.map (vendor) 9.43 MB [initial] [rendered] Time: 6775ms Commented Oct 3, 2019 at 17:27
  • Not sure about those lines. but did you tried the suggestions mentioined in the above link and did it helped? Commented Oct 3, 2019 at 17:40
  • Yes i tried and get in the Chrome console this errors: core.js:9110 ERROR Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule)[EventOverviewPageComponent -> ExportService]: StaticInjectorError(Platform: core)[EventOverviewPageComponent -> ExportService]: NullInjectorError: No provider for ExportService! Commented Oct 3, 2019 at 17:46

2 Answers 2

25

Solution targetting Angular8+ Projects:

This is a known bug, caused due to the incompatibility of exceljs with the version of @types/node. I faced similar issue with Angular 10.

2 possible solutions exists:

  1. Recommended: Update your tsconfig.app.json file with "types": ["node"]

enter image description here

  1. If you are okay without having type support, then you can simply use the below import:
    import * as Excel from "exceljs/dist/exceljs.min.js";
Sign up to request clarification or add additional context in comments.

1 Comment

In my case this worked only if applied to tsconfig.app.json in the project root.
3

Just Open index.d.ts file from yours exceljs node_modules

enter image description here

and replace this line dictionary: Buffer | NodeJS.TypedArray | DataView | ArrayBuffer; // deflate/inflate only, empty dictionary by default

with this

dictionary: Buffer | DataView | ArrayBuffer; // deflate/inflate only, empty dictionary by default

and then just ng serve

2 Comments

LOL! What about the next time they install their dependencies??? Would you expect them to change the code in their node modules every time?
you can use package-patch if you HAVE to go with this approach

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.