I want to import xlsx
.
So, i install xlsx
using npm install xlsx
.
And import xlsx
module. import * as XLSX from 'xlsx';
(Also I try import { foo, bar } from 'xlsx';
)
And run this code with Angular cli. ng serve
.
I use it.
Angular CLI: 1.6.1
Node: 6.11.3
OS: win32 x64
Angular: 2.4.10
... common, compiler, compiler-cli, core, forms, http
... platform-browser, platform-browser-dynamic
@angular/cli: 1.6.1
@angular/router: 3.4.10
@angular/tsc-wrapped: 0.5.2
@angular-devkit/build-optimizer: 0.0.36
@angular-devkit/core: 0.0.22
@angular-devkit/schematics: 0.0.34
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.1
@schematics/angular: 0.1.11
@schematics/schematics: 0.0.11
typescript: 2.0.10
webpack: 3.10.0
please help. thanks.
This is not the way to add 3 party library which does not support import or ES6 functionality. Instead, you can add xlsx library in angular-cli.json file under script tag.
// replace it with xlsx library
"scripts": [
"../node_modules/lodash/lodash.min.js"
],
And then in your component add below snippet and use it.
import * as xlsx from "xlsx";