Skip to content

Commit b943763

Browse files
authored
[php-wasm/universal] Try require() before dynamic imprt in comlink-sync.ts (#2363)
## Motivation for the change, related issues #2317 introduced a dynamic import in a CJS code path (`comlink-sync.ts`). Node 20 requires a `--experimental-vm-modules` flag to run dynamic imports in such a context. This PR tries calling `require()` first to make it all work again. ## Testing Instructions (or ideally a Blueprint) Confirm the `test-built-npm-packages` test passed.
1 parent a262577 commit b943763

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/php-wasm/universal/src/lib/comlink-sync.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,15 @@ export class NodeSABSyncReceiveMessageTransport {
147147

148148
static async create() {
149149
if (!NodeSABSyncReceiveMessageTransport.receiveMessageOnPort) {
150-
NodeSABSyncReceiveMessageTransport.receiveMessageOnPort =
151-
await import('worker_threads').then(
152-
(m) => m.receiveMessageOnPort
153-
);
150+
try {
151+
NodeSABSyncReceiveMessageTransport.receiveMessageOnPort =
152+
require('worker_threads').receiveMessageOnPort;
153+
} catch {
154+
NodeSABSyncReceiveMessageTransport.receiveMessageOnPort =
155+
await import('worker_threads').then(
156+
(m) => m.receiveMessageOnPort
157+
);
158+
}
154159
}
155160
return new NodeSABSyncReceiveMessageTransport();
156161
}

0 commit comments

Comments
 (0)