I have a monorepo using Lerna that I trying to build with Gitlab CI. Running lerna run build
locally builds everything successfully.
The Dockerfile that Gitlab tries to execute looks a bit like this:
FROM node:16 AS common
WORKDIR /usr/src/app
RUN yarn global add lerna
COPY . .
RUN lerna bootstrap --include-dependencies
RUN lerna link
RUN yarn
# yarn build === lerna run build
RUN yarn build
Which results in the following errors:
Cannot find module '@project/common' or its corresponding type declarations.
import { SomeClass } from '@project/common';
Is there any step I am missing? Thanks in advance!
I was able to fix this issue by changing the Dockerfile. Running yarn
before running lerna bootstrap
and removing yarn build
resolved the errors.
My Dockerfile now looks like this:
FROM node:16 AS common
WORKDIR /usr/src/app
RUN yarn global add lerna
COPY . .
RUN yarn
RUN lerna bootstrap --include-dependencies
I can definitely attribute the errors to my limited knowledge of Lerna, but I hope this answer can still help others with similar issues.