Hey :wave: , I am banging my head against a wall t...
# typescript
b
Hey 👋 , I am banging my head against a wall trying to get prisma to work inside a dynamic provider. I always get the
Error serializing '() => provider...
basically meaning that the dynamic provider could not be serialized (I expected this). But I cannot for the life of me figure out how to exclude the
@prisma/client
package from being serialized. I tried: • Custom typescript compilation • Using
await("@prisma/client")
•
deploymentOnlyModule
(found this in the code, but does not seem to work) •
runtimeDependencies
(pretty sure this only applies to the serialized lambda functions) • I tried to search for the code that excludes
aws-sdk
to piggyback on that, but I could not actually find it... Any help is appreciated!
m
Any code you can share? I always find it easier to debug this sort of thing when I have something to look at.
b
Sure no problem. I created a small example project: https://github.com/skirsten/test-pulumi-prisma
m
thanks! that’s helpful. here’s what I get when I run this example myself, which I’m guessing you see as well:
Copy code
'() => provider': index.js(28,47): captured
      variable 'provider' which indirectly referenced
        function 'create': edge-node-provider.ts(36,10): which captured
          variable 'prisma' which indirectly referenced
            '(userArgs) => { const callsite = get ...': index.js(42810,9): which captured
              variable 'client' which indirectly referenced
                function 'setMaxListeners': which captured
                  'NumberIsNaN', a function defined at
                    function 'isNaN': which could not be serialized because
                      it was a native code function.
    
    Function code:
      function isNaN() { [native code] }
so the issue is that the call to
prisma.node.create
ultimately calls into the native JS function
isNaN
, which can’t be serialized: https://www.pulumi.com/docs/intro/concepts/function-serialization/#known-limitations-when-capturing-values this limitation is also mentioned in the dynamic providers documentation: https://www.pulumi.com/docs/intro/concepts/resources/dynamic-providers/#how-dynamic-providers-work
✅ 1
i haven’t used prisma before, so i can’t speak to what your options might be for working around this 🤔
b
Yes, I also came to the conclusion that the serialization is simply not possible. I don't think there are any workarounds from Prisma's side. I was hoping there is some way to exclude the whole package from serializing on Pulumi's side like the internal node modules. I know that this has some drawbacks, but I am willing to accept these if it means I can get this to work somehow.
The only other idea/workaround I had was to invoke a different node process in the dynamic provider and do all the prisma stuff in there. This way the Prisma code will not get serialized. The drawback is that I lose type checking and am adding unnecessary complexity and failure modes 😕
I managed to workaround the issue by doing this:
Copy code
async create(inputs: EdgeNodeInputs) {
  const proc = execFileSync("dist/lifecycle.js", [
    "create",
    JSON.stringify([inputs]),
  ]);
  return JSON.parse(proc.toString());
},
async delete(id, props: Node) {
  const proc = execFileSync("dist/lifecycle.js", [
    "delete",
    JSON.stringify([id, props]),
  ]);
  return JSON.parse(proc.toString());
},
Basically, I moved all of the critical code into a different file that is also compiled and just execute it 🙂 . Its a bit hacky but it works great. Also it allows me greater control than the
local.Command
m
Oh nice! Well done.
Glad you were able to figure something out.