Async Gzip throws error saying to use Node 12+ but already running Node 14+
See original GitHub issueIssue Description
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:
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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Actually, all that error really means is “I couldn’t
require
theworker_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 dynamicrequire
doesn’t exist in an ESM environment. I’ll look into a solution, thanks for the report.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.