Create docker image of project that uses yarn link

  docker, javascript, next.js, reactjs, yarnpkg

In my NextJS project I use yarn as the package manager and decided to use yarn link to have import aliases/absolute imports. This is a neat feature of yarn and the recommended way to use aliases if you use yarn. However, after I implemented it, my docker image creation script broke. The image creation fails on step 6, which is the actual build. Everything works beautifuly if I run yarn dev or yarn build, but docker doesn’t seem to undertand I’m using aliases. Here’s the script I ran the the outputs:

Scripts: docker build --pull --rm -f dockerfile -t my-ui . && docker run -d --name my-ui -p 80:80 my-ui


 => CACHED [builder 1/6] FROM[email protected]:dc98dac24efd4254f75976c40bce46944697a110d06ce7fa47e726847  0.0s 
 => [internal] load build context                                                                                                4.7s 
 => => transferring context: 2.46MB                                                                                              4.6s 
 => [builder 2/6] COPY package.json yarn.lock ./                                                                                 0.1s 
 => [builder 3/6] RUN yarn install --ignore-engines && mkdir /my-ui && mv ./node_modules ./my-ui               364.1s 
 => [builder 4/6] WORKDIR /my-ui                                                                                         0.0s 
 => [builder 5/6] COPY . .                                                                                                      15.2s 
 => ERROR [builder 6/6] RUN yarn run build

The error I get is the following: Type error: Cannot find module 'style/icons/More' or its corresponding type declarations.

This occurs right in the first component of the project. I searched and found nothing on yarn-link and docker. How do I make docker understand that style/* is an alias and be able to find the corresponding modules?

Source: Docker Questions