0

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?

2
  • I can see some reasons why this package.json would 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? Commented Aug 13, 2024 at 11:50
  • The builds are completely fine, yes, both locally and on env. I'm not sure if it is worth digging into build logs, as it's huge on the AWS build pipeline (considering all the prep. steps) and almost blank locally. By the way, I've worked it around by adding a post-build command that - removes the old common folder from node_modules - copies common workspace folder content into the node_modules That somehow proves my idea about the issues with symlinks when they got archived into a .zip artefact. But that's far from the clear solution I'm looking for... Commented Aug 13, 2024 at 16:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.