4

When I tried to use exceljs in Angular-6 like so

import * as excel from 'exceljs'

createExcel() {
  let workbook = new excel.Workbook()
}

even I just initialize a class and got this error. If I comment out this line let workbook = new excel.Workbook() then error gone

./node_modules/fs-constants/browser.js Module not found: Error: Can't resolve 'constants' in 'D:\Developer\spire-client\node_modules\fs-constants'

enter image description here

2 Answers 2

11

You could import it as follow

import * as Excel from 'exceljs';

after that, you can use Exceljs:

const myWorkbook = new Excel.Workbook()

or

import * as Excel from "exceljs/dist/exceljs.min.js";
import * as ExcelProper from "exceljs";

let workbook: ExcelProper.Workbook = new Excel.Workbook();

As long as you just use the import from exceljs for type definitions and only use functions from the import from exceljs/dist/exceljs.min.js, the app will run just fine and you still get type safety.

ref: https://www.npmjs.com/package/exceljs#create-a-workbook https://github.com/guyonroche/exceljs/issues/348#issuecomment-320690232

Sign up to request clarification or add additional context in comments.

4 Comments

as you proposed me this solution, at the same time I found it on https://github.com/guyonroche/exceljs. Thanks
Yes sir, most of the things like configurations and import you can get it from github issues page itself. Since I worked with Data Driven (Viz) websites. I used exceljs and glad you found the solution. and I added the ref too
If above doesn't work use this import * as ExcelJS from "exceljs/dist/exceljs.min.js"; let workbook = new ExcelJS.Workbook(); Accessing it with name ExcelJS solved issue. Hope this helps.
Updating import to import * as Excel from "exceljs/dist/exceljs.min.js"; worked
-1

Import like this

import * as Excel from "exceljs/dist/exceljs.min.js";

and declare

const workbook = new Excel.Workbook();

It will work.

1 Comment

He has imported excel and excelproper in two lines and first one will not resolve the error alone.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.