I've created a monorepo with nodejs + typescript to publish a rest endpoint using yarn workspaces. This server will run on Google Cloud Run and use Google Container Registry.
The structure is the following
my-project /
|
-> common/
package.json
|
-> server/
-> src
Dockerfile
package.json
|
-> client/
(react client that consume what server produce)
Common is a "shared" folder across projects in order to have a single package for types. I used the naming convention @my-project/common as the name of the common package to avoid collisions.
Then, I reference inside my server's code the common package:
in server's package json
"dependencies": {
...
"@my-project/common": "1.0.0",
...
}
then in the actual code
import { MyType } from '@my-project/common/type'
If it is any worth, here's also the Dockerfile:
FROM node:15-alpine
WORKDIR /usr/src/app
COPY package*.json ./
RUN yarn install
COPY ./dist ./
CMD [ "node", "server.js" ]
The build chain is
- cd to server's folder
- call build script with
yarnthat created thedist/folder with the compiled code - exec
gcloud builds submit --tag gcr.io/my-gcp-project-12345/my-gcp-projectto push to GCR
Here's the problem: Cloud Build can't find the common package:
An unexpected error occurred: "https://registry.yarnpkg.com/@my-project%2fcommon: Not found".
Is it possible to find a solution to this, without pushing the common package to a private registry?