Yarn
Installation
- Install
NodeJS
bynvm
is preferred.
npm install -g yarn # Globally install yarn first
cd ~/path/to/project
yarn set version berry # Set your project's yarn as version 2
version
- yarn version issues.
Refer to https://yarnpkg.com/getting-started/install
Run which yarn
you got /usr/local/bin/yarn
.
Run ~/yarn --version
you got 1.22.10
.
Run ~/your_project/yarn --version
you got 2.0.0-rc.31
. That is right. Because this project is using yarn 2!
Docker
Docker yarn start
got:
Usage Error: The project in /Users/lanezhang/projects/sauron/frontend/package.json doesn't seem to have been installed - running an install there might help
or yarn .pnp.js Error: Not a zip archive
.
Both the two errors are caused by the failure of yarn install
.
You can find errors like YN0018: │ yargs@npm:12.0.5: The remote archive doesn't match the expected checksum
.
So try to make yarn install
succeed first.
Solution:
Dockerfile
:
frontend/Dockerfile
:
FROM node
WORKDIR /code/frontend
RUN yarn cache clean
RUN yarn install
EXPOSE 3000
CMD ["yarn", "start"]
docker-compose.yml
frontend:
build: ./frontend
volumes:
- ./frontend:/code/frontend
- https://stackoverflow.com/questions/39990017/should-i-commit-the-yarn-lock-file-and-what-is-it-for The npm client installs dependencies into the node_modules directory non-deterministically. This means that based on the order dependencies are installed, the structure of a node_modules directory could be different from one person to another. These differences can cause “works on my machine” bugs that take a long time to hunt down. Yarn resolves these issues around versioning and non-determinism by using lockfiles and an install algorithm that is deterministic and reliable. These lockfiles lock the installed dependencies to a specific version, and ensure that every install results in the exact same file structure in node_modules across all machines.