question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Async Gzip throws error saying to use Node 12+ but already running Node 14+

See original GitHub issue

How to reproduce

The problem

Hi I’m trying to gzip some files in a .then() promise chain so I tried using gzipAsync() but received the following error:

Error: async operations unsupported - update to Node 12+ (or Node 10-11 with the --experimental-worker CLI flag)
    at Immediate.<anonymous> (file:///home/today/_/work/haptic/node_modules/fflate/esm/index.mjs:34:42)
    at processImmediate (internal/timers.js:456:21)

I’m running Node v14.2.0. The file is ESM via "type": "module" in package.json. The file imports fflate like this:

import esbuild from 'esbuild';
import { gzip, gzipSync } from 'fflate';
import { readFile, writeFile } from 'fs/promises';
// ...

Here’s the code that throws on L47:

image

If I replace L47 with res(gzipSync(readData, { consume: true, level: 9 })); then it’s fine. It’s also fast enough that I’m not reporting an issue with Sync vs Async, just that the error message might be wrong if it’s telling people to update to 12+.

Thanks!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
101arrowzcommented, Apr 26, 2021

Actually, all that error really means is “I couldn’t require the worker_threads package from the standard library,” which I assumed meant that you were in too old a version of Node. However, in this case the issue is probably that dynamic require doesn’t exist in an ESM environment. I’ll look into a solution, thanks for the report.

0reactions
101arrowzcommented, Apr 27, 2021

Yes, if the files are small (say under 300kB) typically the cost of creating a worker thread outweighs the benefit of concurrently compressing all the files at once. So I would suggest sticking with the sync version (but obviously the bug was something that needed to be fixed regardless). Thanks again for the report.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I want to use Node 14 to run my project but it always runs on ...
node. js - I want to use Node 14 to run my project but it always runs on Node 12. How to fix...
Read more >
Node incorrectly throws ERR_UNHANDLED_REJECTION on ...
If I am making my own private code, and the p.then(someFn) is not passed around to anyone, then I effectively have caught errors...
Read more >
Errors | Node.js v18 API
readFile() is called asynchronously. By the time the callback has been called, the surrounding code, including the try…catch block, will have already exited....
Read more >
Node.js v19.3.0 Documentation
Asserts that the function fn does not throw an error. Using assert.doesNotThrow() is actually not useful because there is no benefit in catching...
Read more >
15 Common Error Codes in Node.js and How to Fix Them
Want to centralize and monitor your Node.js error logs? Head over to Logtail and start ingesting your logs in 5 minutes. 1. ECONNRESET....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found