Hello, I have this repo with multiple sst/cdk stac...
# sst
p
Hello, I have this repo with multiple sst/cdk stacks (one per region)). I was trying to move the common dependencies (basically all) to the root folder but I didn't manage to do that. Has anyone else tried to do something similar?
j
Hey Paulo, what's the issue you are running into? Are you getting an error?
p
Hey @Jay. I got some. I first tried to simply delete all deps from my sub folder
Copy code
root
|-- region-a
|   |-- sst.json
|   |-- package.json (no deps)
|
|-- region-b
|   |-- sst.json
|   |-- package.json (no deps)
|
|-- package.json (all deps)
running
npx sst deploy
from the region folder, I got this
Copy code
npx: installed 1 in 1.474s
command not found: sst
I moved the
@serverless-stack/cli
to the region folder and got this
Copy code
Preparing your SST app
Transpiling source
 > node_modules/@aws-cdk/core/lib/private/runtime-info.js: warning: Indirect calls to "require" will not be bundled (surround with a try/catch to silence this warning)
    15 │     for (const fileName of Object.keys(require.cache)) {
       ╵                                        ~~~~~~~

 > node_modules/@aws-cdk/core/lib/private/runtime-info.js: warning: Indirect calls to "require" will not be bundled (surround with a try/catch to silence this warning)
    64 │     const mod = require.cache[fileName];
       ╵                 ~~~~~~~

 > node_modules/@aws-cdk/custom-resources/lib/aws-custom-resource/runtime/index.js: error: Could not read from file: /tmp/node_modules/aws-sdk
    76 │                 AWS = require('/tmp/node_modules/aws-sdk');
       ╵                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~

2 warnings and 1 error
There was a problem transpiling the source.
then, I moved
@serverless-stack/resources
to the region folder and got this:
Copy code
Preparing your SST app
Transpiling source
 > node_modules/@aws-cdk/core/lib/private/runtime-info.js: warning: Indirect calls to "require" will not be bundled (surround with a try/catch to silence this warning)
    15 │     for (const fileName of Object.keys(require.cache)) {
       ╵                                        ~~~~~~~

 > node_modules/@aws-cdk/core/lib/private/runtime-info.js: warning: Indirect calls to "require" will not be bundled (surround with a try/catch to silence this warning)
    64 │     const mod = require.cache[fileName];
       ╵                 ~~~~~~~

2 warnings
Linting source
Deploying stacks
The deployment seems to work, but with these warnings, so I didn't try anything else
j
Ah got it. Just tried this. Yeah these warnings are because esbuild is traversing all your dependencies and those have some issues. SST fixes this by looking at all the dependencies in your
package.json
and ignoring them automatically. But since the
package.json
in your sub-dir doesn't have all those dependencies (
aws-cdk
), it's not able to ignore them. A couple of solutions. You can just ignore these warnings for now. Or disable esbuild bundling (https://docs.serverless-stack.com/constructs/Function#bundle) if you get errors instead or warnings. Or for this setup, use Yarn Workspaces. That way, you can still list all the dependencies in the sub-dir correctly, and Yarn will lift all the dependencies to the root and manage it for you.
I created a new issue to fix this https://github.com/serverless-stack/serverless-stack/issues/102 in the future. But it's a little lower priority for now I think.