https://pulumi.com logo
Title
w

wonderful-bird-78843

05/02/2022, 11:03 PM
One more fun function serialization problem!
import { promisify } from "util";
import { execFile as execFileReal } from 'child_process';

const execFile = promisify(execFileReal);
and then in a sns
Topic.onEvent()
I'm doing:
try {
            const { stdout } = await execFile('curl', args);
            console.log("stdout:", stdout);
            msg.Response = stdout;
}
On
up
, I'm getting:
Diagnostics:
  pulumi:pulumi:Stack (mcurl-typescript-mcurl):
    error: Error serializing '(ev, ctx) => __awaiter(this, void 0, ...': index.ts(137,57)

    '(ev, ctx) => __awaiter(this, void 0, ...': index.ts(137,57): captured
      'execFile', a function defined at
        '(...args) => { const { promise, reso ...': node:child_process(231,9): which captured
          'orig', a function defined at
            function 'execFile': node:child_process(278,17): which captured
              'ArrayIsArray', a function defined at
                function 'isArray': which could not be serialized because
                  it was a native code function.
This seems to suggest that the import from
child_process
should just be serialized into an import on the server, no?
For the reasons cited previously, modules are captured in a special but intuitive fashion. When a module is captured in code, it is translated into an idiomatic require call in the serialized JavaScript code.
This form of module capturing only applies to external modules that are referenced, such as modules that are directly part of Node, or are in the node_modules directory.
Am I missing something?
ahh, bah... I moved the
const execFile = promisify(execFileReal);
into the callback, and that fixed it
is this a bug?