Skip to content

Commit 7239e9b

Browse files
committed
Disable advanced serialization (workaround nodejs/node#34797)
1 parent b0a6bb4 commit 7239e9b

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
const path = require('path');
33
const EventEmitter = require('events');
44

5+
const { deserializeError } = require('serialize-error');
6+
57
const execa = require('execa');
68

79
class Client {
@@ -24,7 +26,6 @@ class Client {
2426
path.join(__dirname, 'worker.js'),
2527
...execaWorkerArguments,
2628
], {
27-
serialization: 'advanced',
2829
stdio: [ 'inherit', 'inherit', 'inherit', 'ipc' ],
2930
...execaOptions,
3031
});
@@ -42,6 +43,10 @@ class Client {
4243
}
4344

4445
__onWorkerMessage({ type, payload, error, meta }) {
46+
if (error) {
47+
error = deserializeError(error);
48+
}
49+
4550
if (type === '__resolveReady') {
4651
this.__resolveReady();
4752

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"tglib": "^3.0.5"
3636
},
3737
"dependencies": {
38-
"execa": "^4.0.3"
38+
"execa": "^4.0.3",
39+
"serialize-error": "^7.0.1"
3940
}
4041
}

worker.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
const { serializeError } = require('serialize-error');
3+
14
const handler = {
25
__init({ tglibModuleName = 'tglib', ...options }) {
36
const { Client } = require(tglibModuleName);
@@ -10,7 +13,7 @@ const handler = {
1013
}),
1114
error => process.send({
1215
type: '__rejectReady',
13-
error,
16+
error: serializeError(error),
1417
}),
1518
);
1619

@@ -53,7 +56,7 @@ const handler = {
5356
}, error => {
5457
process.send({
5558
type: '__response',
56-
error,
59+
error: serializeError(error),
5760
meta,
5861
});
5962
});
@@ -90,15 +93,15 @@ process.on('message', ({ type, payload, meta }) => {
9093
process.on('uncaughtException', error => {
9194
process.send({
9295
type: '__uncaughtException',
93-
error,
96+
error: serializeError(error),
9497
});
9598
process.disconnect();
9699
});
97100

98101
process.on('unhandledRejection', error => {
99102
process.send({
100103
type: '__unhandledRejection',
101-
error,
104+
error: serializeError(error),
102105
});
103106
process.disconnect();
104107
});

yarn.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5164,6 +5164,13 @@ serialize-error@^2.1.0:
51645164
resolved "https://registry.yarnpkg.com/serialize-error/-/serialize-error-2.1.0.tgz#50b679d5635cdf84667bdc8e59af4e5b81d5f60a"
51655165
integrity sha1-ULZ51WNc34Rme9yOWa9OW4HV9go=
51665166

5167+
serialize-error@^7.0.1:
5168+
version "7.0.1"
5169+
resolved "https://registry.yarnpkg.com/serialize-error/-/serialize-error-7.0.1.tgz#f1360b0447f61ffb483ec4157c737fab7d778e18"
5170+
integrity sha512-8I8TjW5KMOKsZQTvoxjuSIa7foAwPWGOts+6o7sgjz41/qMD9VQHEDxi6PBvK2l0MXUmqZyNpUK+T2tQaaElvw==
5171+
dependencies:
5172+
type-fest "^0.13.1"
5173+
51675174
set-blocking@^2.0.0:
51685175
version "2.0.0"
51695176
resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7"

0 commit comments

Comments
 (0)