Project structure "Sharing code between services"

Hi, I came across the AWS reference architecture where each function has a package.json: lambda-refarch-webapp/todo-src/completeTodo at master · aws-samples/lambda-refarch-webapp · GitHub

I also came across Structuring a Real-World Serverless App but that didn’t have a real Git repo for me to study, so I didn’t actually understand how to manage “Sharing code between services”.

For example I’ve created a minimal reproducible example here:

But when I include …/log.js from bar, log.js is unable to discover bar’s package.json. So how does one organise their code base to make it work?

Many thanks,

It’s going to depend on the language and packaging. For Node options including

  1. Use webpack
  2. Put shared code into a package then install it.
1 Like

Thanks, in the end I’ve gone for the single package.json where the serverless.yml is.

Was trying esbuild Confused as to how to structure shared code · Issue #210 · floydspace/serverless-esbuild · GitHub though bizaarely one of my functions fails with

2021-10-15T07:08:11 2021-10-15T07:08:11.687Z undefined ERROR Uncaught Exception {"errorType":"TypeError","errorMessage":"Cannot destructure property 'dir' of 'T.package' as it is undefined.","stack":["TypeError: Cannot destructure property 'dir' of 'T.package' as it is undefined."," at node_modules/esm/esm.js (/var/task/v1/index.js:50982:20)"," at __require (/var/task/v1/index.js:41:44)"," at node_modules/@digitalbazaar/http-client/index.js (/var/

Perhaps some commonJS/requireJS issue, idk. I do know I miss Golang!