Is there an easy way to use the same lib code (my ...
# help
a
Is there an easy way to use the same lib code (my own) in an SST lambda backend and react frontend (embedded in the same project) without duplicating the file? I tried importing the lib in the react code, but got an error message that it can't import code from outside its own src folder
a
How does your folder structure look like? Are you using workspaces? Haven't tried something like this myself (yet) but some more info would be useful. Also, what is throwing the error? sst?
a
I think the error comes from react
the react frontend just sits in an own folder called "frontend" in the top level of the sst project
so project/src is lambda source and project/frontend/src is react source
t
This generally is tricky to setup
particularly between backend and frontend
Are you sure you can't extract this functionality to its own package?
a
i can but I was hoping it would be easier
i can also use git submodules or something
a
Monorepo is the easiest to work with, but takes some effort to setup. The Serverless Stack team has an example using Lerna. NPM Workspaces are available starting in v7, and are simpler to learn. I've done the approach of a separate repo for shared code, git tag for version, and then git dependencies in package.json. It works, but you need to commit each shared change before you can try using it.
j
a
@Jay This doesn't show shared code between frontend and backend, though, but I'll see if I can adapt it
I'll probably have to make a frontend and a shared folder and then configure the shared folder similar to how it's done with core in the example, right?
so that I can do
import { Foo } from "@acme/shared"