Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_STRING_TOO_LONG #2022

Closed
piniu opened this issue Jun 23, 2020 · 4 comments
Closed

ERR_STRING_TOO_LONG #2022

piniu opened this issue Jun 23, 2020 · 4 comments

Comments

@piniu
Copy link

piniu commented Jun 23, 2020

Getting this error when trying to read xlsx file (86MB) also tried to stream and buffer but getting the same error. Any idea or direction?
`
const XLSX = require('xlsx');
let filePath = data.filePath;

            const readable = fs.createReadStream(filePath);

            function process_RS(stream, callback) {
                var buffers = [];
                stream.on("data", function (data) {
                    buffers.push(data);
                });
                stream.on("end", function () {
                    let buffer = Buffer.concat(buffers);
                    const workbook = XLSX.read(buffer, { type: "buffer", WTF: true });
                    const sheetNames = workbook.SheetNames;
                    const worksheet = workbook.Sheets[sheetNames[0]];
                    const result = XLSX.utils.sheet_to_json(worksheet);
                    callback(result);
                });

`

@SheetJSDev
Copy link
Contributor

To be sure, is the read failing or the sheet_to_json call? NodeJS ERR_STRING_TOO_LONG is governed by kMaxLength in v8 https://github.com/nodejs/node/blob/master/deps/v8/include/v8.h#L2957 which is ~256 MB or ~512MB depending on size_t

@piniu
Copy link
Author

piniu commented Jun 28, 2020

sheet_to_json is failing
thanks

@SheetJSDev
Copy link
Contributor

This is an issue with NodeJS and a hard limit on the size of the resulting output.

XLSX.stream.to_json should be used in node. It creates an object-mode stream:

/* to_json returns an object-mode stream */
var stream = XLSX.stream.to_json(worksheet, {raw:true});

/* the following stream converts JS objects to text via JSON.stringify */
var conv = new Transform({writableObjectMode:true});
conv._transform = function(obj, e, cb){ cb(null, JSON.stringify(obj) + "\n"); };

stream.pipe(conv); conv.pipe(process.stdout);

@iRoachie
Copy link

iRoachie commented Nov 28, 2021

Hey guys, i have this exact problem but it fails at XLSX.read(data). Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants