Build failing due to symlink issue, help?!

I’m trying to Balena push my application to a production environment but the build keeps failing. It’s the exact same repo as was successfully deployed a week ago.

Errors are as follows:
Removing intermediate container fc73b93c08ed
—> 1c1979adf5a4
Step 8/17 : RUN npm install -g yarn typescript
—> Running in 6e792b169a1e
/usr/local/bin/tsc -> /usr/local/lib/node_modules/typescript/bin/tsc
/usr/local/bin/tsserver -> /usr/local/lib/node_modules/typescript/bin/tsserver
npm ERR! code
EEXIST
npm ERR! syscall symlink

npm ERR!
 path
 ../lib/node_modules/yarn/bin/yarn.js

npm
 ERR!
 
dest /usr/local/bin/yarn

npm 
ERR! errno -17

npm ERR!
 EEXIST: file already exists, symlink '../lib/node_modules/yarn/bin/yarn.js' -> '/usr/local/bin/yarn'

npm ERR! File exists: /usr/local/bin/yarn

npm 
ERR!
 Remove the existing file and try again, or run npm

npm 
ERR! with --force to overwrite files recklessly.


npm 
ERR!
 A complete log of this run can be found in:
npm 
ERR!
     /root/.npm/_logs/2020-01-07T22_43_32_361Z-debug.log

I’ve tried updating the FROM base image in the docker file, but errors persist.

Dockerfile is as follows:

FROM balenalib/raspberrypi3-node:10-run-20191122

# Arguments - docker-compose can override them on build and run
RUN apt-get update && apt-get install -yq \
    python build-essential && \
    apt-get install -y curl &&  \
    apt-get clean && rm -rf /var/lib/apt/lists/*
# NPM token for private packages
ARG NPM_TOKEN

ENV VERSION=1.0.6


# We only want warnings from NPM
ENV NPM_CONFIG_LOGLEVEL warn

RUN npm install -g yarn

# Set a working directory
WORKDIR /app

# Copies the package.json first for better cache on later pushes
COPY package.json package.json

# Copy the app
COPY . /app

# Install the packages
RUN yarn install --force --frozen-lockfile

RUN yarn build

# ─────────────────────────────────  Command  ──────────────────────────────────

CMD ["yarn","start"]

Apparently the base container was updated that broke the build, assuming it was updated to include yarn.

changing the container to a specific build: FROM balenalib/raspberrypi3-node:10-run-20191122 fixed the problem

I’ve created the following Github issue with a couple of workarounds that I found to work for me:

Until the root cause is further clarified, I think that pinning the base image to the previous version is the “safest solution”:

FROM balenalib/raspberrypi3-node:10-run-20191122

My assumption is that yarn was added to the base image, I removed npm install -g yarn from my docker file and the build succeeded ( using one of the previous base images that was failing ).

I’m assuming that changing it to npm install -g yarn --force would also solve the problem, but I haven’t tested that.

Hi,

Yarn was added to the balenalib base images long time ago, even this image balenalib/raspberrypi3-node:10-run-20191122 has yarn pre-installed (v 1.19.1) so I’m surprised that you didn’t have this issue before.

The changes in balenalib/raspberrypi3-node:10-run-20191223 image are node, npm and yarn updated to v10.18.0, v6.13.4 and v1.21.1 respectively so I guess there are changes in npm or node that cause the issue. However, as our node images have yarn pre-installed so I think you can just remove npm install -g yarn from your Dockerfile.