I have a monorepo with frontend, backend and my-common yarn workspaces.
+-- node_modules
+-- package.json
+-- tsconfig.json
+-- buildspec.yml
+-- my-common
| +-- package.json
| +-- tsconfig.json
| +-- src
| +-- index.ts
+-- backend
| +-- package.json
| +-- tsconfig.json
| +-- src
| ...
+-- frontend
| +-- package.json
| +-- tsconfig.json
| +-- src
| ...
root package.json is the following:
{
"main": "backend/dist/main.js",
"name": "app-name",
"private": true,
"scripts": {
"build": "yarn workspace my-common build && yarn workspace backend run build",
"build:fe": "yarn workspace my-common build && yarn workspace frontend run build",
"start": "node backend/dist/main.js",
"start:dev": "yarn workspace backend start:dev & yarn workspace frontend start:dev"
},
"version": "0.0.1",
"workspaces": [
"frontend",
"backend",
"my-common"
]
}
The frontend is built and deployed with AWS Amplify without issues.
The backend is delivered with CodePipline being built with CodeBuild.
It passes through all the stages successfully, but the instance can't start because of
Error: Cannot find module 'my-common'
And really, the my-common package is not present in node_modules when I download the artefact archive from CodeBuild.
At the same time, when I'm trying to replicate all steps locally (on Mac), I can see the symlink in the node_modules to the my-common workspace folder as expected, even after archive\unarchive.
So, how is it possible that the symlink got lost during the build\archive stage? Is there any way to force npm to include\copy folder instead of symlink it? Is there any clear way to arrange such a build\deployment correctly without a hack?
package.jsonwould fail. But if you're saying that all build stages are working, the reasons I found would not apply. Can you share the logs of your build?