2

Prior to cloning the substrate-front-end-template repo with tag "monthly-2022-02" I installed the following since I was building it from a Dockerfile using pre-built Docker image node:gallium-alpine:

  • Yarn 1.22.19 (running yarn --version outputs 1.22.19). This was bundled with node:gallium-alpine pre-built Docker image.
  • Node.js LTS v16.18.1 (matching contents of .nvmrc that includes lts/gallium and since the CircleCI .circleci/config.yml file is using Node.js 16.14)

But it appeared as though the repository required Yarn 3.1.1 (hence why there is a .yarn folder containing .yarn/releases/yarn-3.1.1.cjs, package.json contains "packageManager": "[email protected]", and a file called .yarnrc.yml whose contents include:

nodeLinker: node-modules

plugins:
  - path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
    spec: "@yarnpkg/plugin-interactive-tools"

yarnPath: .yarn/releases/yarn-3.1.1.cjs

But after you clone the repo and try to install dependencies with yarn it outputs error:

Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation)

1 Answer 1

0

Resolving the issue involved upgrading to Yarn 3.1.1 before running yarn. Followed these Yarn instructions to install its Corepack and the latest Yarn 3.1.1.

If I didn't correctly re-create the .yarnrc.yml file to include plugins and nodeLinker before running yarn then I would get error: TypeError: semantic-ui-css@Semantic-Org/Semantic-UI-CSS#master: Cannot set properties of undefined (setting 'message').

Since we are using Yarn 3.x we still need to explicitly import plugins like interactive-tools into the file. It is also necessary to have nodeLinker: <VALUE> in the file. So re-creating it as follows in the Dockerfile worked to adequately switch to Yarn 3.1.1 first and also resolved the error Usage Error: Couldn't find the node_modules state file - running an install might help (findPackageLocation), so it wasn't necessary to first have to copy across the /.yarn folder and .yarnrc.yml file from the host machine before running yarn (i.e. yarn install).

FROM node:gallium-alpine

WORKDIR /app
ENV PATH=/app/node_modules/.bin:$PATH

COPY package.json .
RUN printf "Pre-built Docker image using built-in Yarn version: "; yarn --version

# it was necessary to install Git first since it uses that dependency
RUN apk update && apk add --update git && rm -rf /var/cache/apk/*
RUN corepack enable \
    && corepack prepare yarn@stable --activate \
    && yarn set version 3.1.1 \
    && yarn plugin import interactive-tools \
    && echo -e "nodeLinker: node-modules\n\n$(cat /app/.yarnrc.yml)" > /app/.yarnrc.yml \
    && cat /app/.yarnrc.yml \
    && printf "Switched to Yarn version: "; yarn --version \
    && yarn install

Note: It would also work with Yarn 3.3.0 if the appropriate files were updated.

Reference: https://github.com/substrate-developer-hub/substrate-front-end-template/issues/259

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.