set_fs undefined #2909

Closed
opened 2023-04-06 14:22:31 +00:00 by jinnzy · 2 comments

hi, how to solve set_fs undefined?

install

npm i --save https://cdn.sheetjs.com/xlsx-0.19.2/xlsx-0.19.2.tgz

test.ts

import { set_fs, utils, version, writeFile } from 'xlsx';
import * as fs from 'fs';
console.log(set_fs)
set_fs(fs);

result:

set_fs undefined
/.../test.ts:4
set_fs(fs);
      ^
TypeError: (0 , xlsx_1.set_fs) is not a function

hi, how to solve set_fs undefined? install ``` npm i --save https://cdn.sheetjs.com/xlsx-0.19.2/xlsx-0.19.2.tgz ``` test.ts ``` import { set_fs, utils, version, writeFile } from 'xlsx'; import * as fs from 'fs'; console.log(set_fs) set_fs(fs); ``` result: ``` set_fs undefined /.../test.ts:4 set_fs(fs); ^ TypeError: (0 , xlsx_1.set_fs) is not a function ```
Owner

Using tsc 5.0.3 with no module override, the following code was generated:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var xlsx_1 = require("xlsx"); // <-- this is using the commonjs build
var fs = require("fs");
console.log(xlsx_1.set_fs);
(0, xlsx_1.set_fs)(fs);

set_fs is only in the ESM builds (the CommonJS build performs require("fs") directly).

There are probably some settings to force TSC to generate proper ESM code, but in the interim we will consider adding set_fs to the CJS build.

Using tsc 5.0.3 with no module override, the following code was generated: ```js "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var xlsx_1 = require("xlsx"); // <-- this is using the commonjs build var fs = require("fs"); console.log(xlsx_1.set_fs); (0, xlsx_1.set_fs)(fs); ``` `set_fs` is only in the ESM builds (the CommonJS build performs `require("fs")` directly). There are probably some settings to force TSC to generate proper ESM code, but in the interim we will consider adding `set_fs` to the CJS build.
Owner

In the next release, set_fs and set_cptable will be exposed in the CJS build.

In the next release, `set_fs` and `set_cptable` will be exposed in the CJS build.
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: sheetjs/sheetjs#2909
No description provided.