Question 2 (Prisma + typecheck): For some reason,...
# help
b
Question 2 (Prisma + typecheck): For some reason, when
typecheck: true
is set, I’m getting type errors. I’ve tried to exclude node_modules in tsconfig but also no luck 🙂 Not my luckiest day.
f
Hey @Branko Gvoka, can I see what your
tsconfig
looks like?
b
Hey @Frank here it is
Copy code
{
  "compilerOptions": {
    "target": "ES2018",
    "module": "commonjs",
    "lib": ["es2018"],
    "declaration": true,
    "strict": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "noImplicitThis": true,
    "alwaysStrict": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noImplicitReturns": true,
    "noFallthroughCasesInSwitch": false,
    "inlineSourceMap": true,
    "inlineSources": true,
    "experimentalDecorators": true,
    "strictPropertyInitialization": false,
    "typeRoots": ["./node_modules/@types"],
    "paths": {
      "@packages/*": ["./packages/*"],
    }
  },
  "include": ["lib", "services", "packages"]
}
Does it have to do with monorepo structure?
f
Yeah… you mentioned you are setting the
srcPath
in the other thread. SST expects the
tsconfig.json
to be inside there - https://docs.serverless-stack.com/constructs/Function#srcpath
Can you try moving the tsconfig.json there and see that works?
b
Yeah, I’ll try and let you know, thanks!
@Frank I’ve tried adding tsconfig in specific service folder, it didnt work. 😢 Here’s the tsconfig
Copy code
{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "baseUrl": "."
  },
  "include": [
    "src"
  ]
}
In the monorepo, we’re running in the root of project
sst start
there it should load according tsconfig I assume Any other hints? 🙂
f
hmm.. can I bug you for a sample repo with the issue? Let me give it a try.
Most monorepo setup I’ve come across from folks in the community has SST app sitting at the root. Similar to this setup - https://github.com/serverless-stack/lerna-yarn-starter
b
Hey @Frank, I’ll try to set one and share for the weekend 🙂
Hey @Frank happy weekend! I’ve created an example repository, tried to reproduce the error and somehow managed to get the cause of the error! 🎉 So in the monorepo setup, we didnt have typescript as dependency at the root package.json, that caused the issue. Once I’ve explicitly added it, it worked. Do you know how come this happened? 🙂 I’d share the repo but we have internal eslint/prettier config that is private npm package. so thats why I didnt attach it here, first I’ve tried with random eslint setup
I’m getting now
Copy code
Cannot find a "tsconfig.json" in the function's srcPath: /Users/.../projectName/services/serviceName
Should I add tsconfig that extends the root one? Can it reference somehow the root automatically? What is best practice I guess? 🙂
f
Hey @Branko Gvoka, btw are you setting the
srcPath
b/c that’s where your
package.json
is?
b
@Frank I’ve set srcPath to point to correct package.json as I was getting this error from Prisma
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");
🙂
f
Let me loop in @Jay. @Jay when you work on adding the SST Prisma example, can you take a look at the issues @Branko Gvoka ran into: 1. Lambda transpiling issue https://serverless-stack.slack.com/archives/C01JG3B20RY/p1625565179170400 2. Typescript issue above 3. If
srcPath
cannot be pointed to the app root (where
tsconfig.js
is), we’d need to support custom
tsconfig.js
path
b
Yeah I think this would be really good, as well as trying to find closest .eslintrc.js to the tsconfig, as I’d like to also include absloute paths for the subproject 🙂
j
Yup, let’s create an issue in GitHub and put this in there
f
@Jay I gather all Prisma related issues/discussions here https://github.com/serverless-stack/serverless-stack/issues/570