Using Node.js v18.12.1, I'm trying to use https://www.npmjs.com/package/xlsx in a node.js EcmaScript module wrote in typescript.
However, when I follow the instructions for Node.js (https://docs.sheetjs.com/docs/getting-started/installation/nodejs#esm-import) like this :
import * as fs from 'fs';
import * as XLSX from 'xlsx';
XLSX.set_fs(fs);
I get the following runtime (not compile time) error:
TypeError: XLSX.set_fs is not a function
What is wrong with this import ?
tsconfig.json:
...
"target": "ESNext",
"module": "ESNext",
...
package.json:
...
"type": "module"
...
Older releases are technically available on the public npm registry as xlsx, but the registry is out of date. The latest version on that registry is 0.18.5
Following these steps solves the problem : https://docs.sheetjs.com/docs/getting-started/installation/nodejs#installation
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With