solve() throws "Unable to parse solution. Too few lines." when output_flag or log_to_console is false
## Summary
In highs-js v1.8.0, calling `solve()` with `output_flag: false` (or `log_to_console: false`) in the options causes the wrapper to throw:
```
Error: Unable to parse solution. Too few lines.
```
The underlying HiGHS solver runs fine and finds the optimum — the failure is in the JS wrapper's solution parsing.
## Root cause
The wrapper appears to capture HiGHS's stdout into an internal buffer (`q` in `build/highs.js`) and parse the solution from it. Setting `output_flag: false` or `log_to_console: false` silences that stream, so `q` ends up empty and `fc()` throws:
```js
function fc(a){if(3>q.length)throw Error("Unable to parse solution. Too few lines."); ... }
```
## Reproduction
```js
const highsLoader = require('highs');
const PROBLEM = `Maximize
obj: x1 + 2 x2
Subject To
c1: x1 + x2 <= 10
Bounds
0 <= x1 <= 5
0 <= x2 <= 5
End`;
(async () => {
const highs = await highsLoader();
// Works:
console.log(highs.solve(PROBLEM, { time_limit: 5 }).Status); // Optimal
// Throws "Unable to parse solution. Too few lines.":
try { highs.solve(PROBLEM, { time_limit: 5, output_flag: false }); }
catch (e) { console.log('threw:', e.message); }
// Same:
try { highs.solve(PROBLEM, { time_limit: 5, log_to_console: false }); }
catch (e) { console.log('threw:', e.message); }
})();
```
I hit this in a browser worker where I wanted to suppress the noisy HiGHS log on each solve. The MIP I was actually solving had ~440 binary vars and ~296 constraints, but the bug reproduces on a trivial 2-variable LP too.
## Workaround
Don't pass `output_flag` or `log_to_console` (or set them to `true`). HiGHS then logs its banner and progress to stdout, but `solve()` returns the parsed solution as expected.
## Suggested fix
Either:
1. Have the wrapper extract the solution through a different channel (e.g., `solution_file` written to the in-memory FS, then read back), so user-facing log flags don't break parsing; or
2. Document that `output_flag` / `log_to_console` are incompatible with `solve()` and ignore them (or warn) when set to `false`.
Option 1 is the friendlier fix — these are standard HiGHS options users naturally reach for.
## Environment
- highs v1.8.0
- Node 22 (also reproduced under jsdom/vitest)
- macOS (darwin)
关闭于 2026-05-28 2 条评论