# help

Adrian Schweizer

02/20/2022, 5:29 PM
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


02/20/2022, 5:36 PM
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?

Adrian Schweizer

02/20/2022, 7:15 PM
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


02/20/2022, 7:56 PM
This generally is tricky to setup
particularly between backend and frontend
Are you sure you can't extract this functionality to its own package?

Adrian Schweizer

02/20/2022, 8:18 PM
i can but I was hoping it would be easier
i can also use git submodules or something

Adam Fanello

02/21/2022, 6:01 PM
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.


02/21/2022, 9:52 PM

Adrian Schweizer

02/22/2022, 10:32 PM
@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"