Does anyone here use a Yarn Workspaces + TypeScrip...
# help
s
Does anyone here use a Yarn Workspaces + TypeScript monorepo setup? I am trying to utilise a shared package within my monorepo, consuming it within my lambdas, but upon executing I get an error saying that imported module does not exist. I was trying to import native TS files in the hope that they would be transpiled and bundled into the output for each lambda.
Copy code
|-- backend
|   |- lambdas
|   |  |- foo.ts (contains: import { isNullOrEmpty } from '@my/lib/strings';)
|   |- package.json
|- lib
    |- strings.ts
    |- package.json (name: "@my/lib")
I am guessing it is looking for a
strings.js
file rather than a
strings.ts
file.
Copy code
Error: Cannot find module '@my/lib/strings'
Any way to tinker with the underlying esbuild config to allow for the transpilation of the shared monorepo package?
🤞
I guess an alternative approach would be to have a single package.json and tsconfig.json at the root and then utilise TS path aliases.
But I like how much cleaner and scoped the dependencies are in my initial approach.
Aha, I figured it out. I had set the srcPath for my functions to be the
backend
folder. I changed it to the root of the project. This seems to have increased the scope, allowing ESBuild to do it's magic. Lovely.
f
Hey @Sean Matheson, glad you figured it out!
@thdxr created this TypeScript monorepo starter, maybe you can see if the setup fits ur usecase https://github.com/serverless-stack/serverless-stack/tree/master/examples/typescript-monorepo