Prisma + sst question Hey guys, I’m trying to use...
# help
b
Prisma + sst question Hey guys, I’m trying to use
@prisma/client
with sst. When I run
sst start
I’m getting
Copy code
Transpiling Lambda code...
 > node_modules/@prisma/client/runtime/index.js:24726:23: error: Could not resolve "_http_common" (mark it as external to exclude it from the bundle)
    24726 │   var common = require("_http_common");
          ╵                        ~~~~~~~~~~~~~~
Did anyone encounter similar problem? I’ve tried to pull this into layer and used externalModules for @prisma/client but it also doesnt pick it up. Here’s Stack snippet in screenshot. I’ve even tried pulling these default into route directly but no luck. Thanks!
t
This is how I create my prisma layer
Copy code
const layer_root = ".build/layer"
  const layer_node = path.join(layer_root, "nodejs")
  const to_copy = [
    "node_modules/@prisma/client",
    "node_modules/@prisma/engines/migration-engine-rhel-openssl-1.0.x",
    "node_modules/@prisma/engines/query-engine-rhel-openssl-1.0.x",
    "node_modules/@prisma/engines/package.json",
    "node_modules/@prisma/engines/dist",
    "node_modules/prisma",
    "node_modules/.prisma",
  ]
  execSync(`rm -rf ${layer_root}`)
  for (let src of to_copy) {
    const parent = path.join(src, "../")
    execSync(`mkdir -p ${layer_node}/${parent}`)
    console.log(`Copying ${src} to ${layer_node}/${parent}`)
    execSync(`cp -a ${src} ${layer_node}/${parent}`)
  }

  const to_delete = [
    "node_modules/prisma/query-engine-rhel-openssl-1.0.x",
    "node_modules/prisma/query-engine-debian-openssl-1.1.x",
    "node_modules/.prisma/query-engine-rhel-openssl-1.0.x",
    "node_modules/.prisma/query-engine-debian-openssl-1.1.x",
  ]
  for (let src of to_delete) {
    execSync(`rm -rf ${src}`)
  }

  const layer = new lambda.LayerVersion(stack, "Prisma", {
    code: lambda.Code.fromAsset(layer_root),
    compatibleRuntimes: [lambda.Runtime.NODEJS_14_X],
  })
  execSync(`rm -rf ${layer_root}`)
and for external modules
Copy code
externalModules: [
      "@prisma/client",
      "prisma",
      ".prisma/client",
      "@prisma/engines",
    ],
b
I’ve found the causing issue https://github.com/prisma/prisma/issues/6564 but for some reason esbuild doesnt include externalModules
@Frank is there a way to use a newer version of esbuild somehow? https://github.com/evanw/esbuild/commit/988ff3fb6e275c4321c636f81869fa8e8adf56ea
Figured it out after debugging sst 😄 as we’re using monorepo, I had to explicitly set srcPath in sst.Api to /services/<service_name> so it picks up externals from appropriate package.json
f
Hey @Branko Gvoka if the
package.json
isn’t at the app root (where
sst.json
is), you’d have to specify a
srcPath
pointing to the package.json.
b
Maybe its supposed to be this way. Since we’re having monorepo setup and would want absolute paths in place internally in the subproject, I would anyways need a tsconfig (that extends root) next to the package.json where srcPath is.