Yarn.lock in a team via git - yarnpkg

A quick question about yarn and yarn.lock in a team setting. When someone updates yarn.lock in git, what is the procedure for developers?
Does yarn automatically figure out that the lock file is newer than node_modules and "figure it out", or do people remove their local node_modules and rerun yarn install?

Yarn won't do any check on node_modules folder when yarn.lock is updated via VCS.
To align node_modules folder with the dependencies listed in yarn.lock, there is no need to delete the folder. Run yarn command instead.

Related

How to uninstall Yarn from a project

I'm a bit confused.
I accidentally installed yarn in a project. I just ran the command yarn that installed the yarn in the project. How do I uninstall yarn from the project?
Do I type in npm uninstall yarn? to uninstall it from a project?
I looked at other solutions and I'm confused.
Run npm uninstall yarn make sure it no longer is listed in your package.json
Delete the yarn.lock file if there is one
If in linux (similar for others I guess):
cd project_directory
Run "npm uninstall yarn"
rm -rf .yarn
rm .yarnrc.yml
rm yarn.lock
in package.json: delete "yarn" lines
in .gitignore (if present): delete "yarn" lines
in README.md (if present): change "yarn" to "npm"
run "grep -irl yarn ." to find any other references

getting YN0028 The lockfile would have been modified by this install, which is explicitly forbidden. using yarn berry and heroku

I'm using yarn berry and heroku and consistently getting the error:
➤ YN0028: │ The lockfile would have been modified by this install, which is explicitly forbidden.
Which suggests that my lockfile does not contain all my listed dependencies. In the yarn docs it says this is easily solved by running yarn install and pushing new lockfile to git. However I've tried this, tried with fresh node_modules, etc with no luck.
Has anyone else experienced this issue using yarn berry + heroku?
My repo is a monorepo using workspaces.
I was able to workaround by setting the env-var YARN_ENABLE_IMMUTABLE_INSTALLS to false, as suggested here.
This is likely a bug in Yarn Berry. I've reported it here: https://github.com/yarnpkg/berry/issues/2948
UPD: I have created a fresh local clone of the repo from GitHub, ran yarn install in it, and it did produce changes in yarn.lock. Committing those changes resolved the CI issue, so disabling YARN_ENABLE_IMMUTABLE_INSTALLS is no longer necessary for me.
The original local repo showed a clean git status, so I still believe it is a bug.
UPD 2: My problem was that one of the Yarn worspaces was checked into git as a git submodule (I have probably created it with a nested .git/ folder and then deleted it). As a result, the workspace content, including a child package.json was not committed into the repo, it only existed in my local repo and not on the remote and CI.
After removing the git submodule and checking the workspace into the repo properly, the YN0028 error stopped happening.
If your ENV doesn't contain any CI variables:
Then it could be your yarn config:
Run yarn config get enableImmutableInstalls and see if it's enabled.
(you can also check why it is enabled by running yarn config --why and looking for enableImmutableInstalls).
If it is true, then run yarn config set -H enableImmutableInstalls false to set the setting's value globally (or without the -H argument to set it only in your current project)
I ran across the same issue. I resolve dit by deleting my cache and then reinstalling the dependencies.
The yarn.lock file was then modified by the time the reinstall had completed.
I believe this may have been because I checked in the cache folder initially, and then reverted it. Not sure if this then caused a discrepancy between my local environment and the checked-in repo.

Clone and setup Repository from Bit Bucket to XCode

joined a new organisation. Never worked on react native repositories before.
I need a quick help on how to clone a React Native repository from bit bucket to Xcode and setup to work only on iOS module.
I have downloaded the repository and open the iOS Folder and opened projectname.xcworkspace file. It opened my project but so many files are missing. So I assume that it is not the right way to do. Please help.
I think you didn't use command of npm install or yarn install then after completed the above command you need to use cd ios(Go to ios directory) and pod install then you should open your projectname.xcworkspace file.
if you have package-lock.json then use npm install and if you have yarn.lock then use yarn install command.

How to install yarn workspace packages without symlink?

I have a yarn workspaces project which looks something like this:
node_modules
packages
shared
test.js
package.json
client
test.js
package.json
server
test.js
package.json
package.json
server.Dockerfile
As you can see, I have a server.Dockerfile, which builds an image of the server that I can push up to different hosting providers such as Heroku or AWS.
I copy packages and package.json into this container:
COPY packages packages
COPY package.json .
And I then install only the dependencies for the server package:
RUN cd packages/server && yarn install
All the dependencies are now in the node_modules folder, and the next thing I think of doing is to delete the packages folder to remove any unnecessary code from the docker image (e.g. the client code):
RUN rm -rf packages
The problem with this is that all the yarn workspace packages inside the node_modules folder are simply symlinks to the packages folder... so I cannot delete that folder.
How do I get yarn install to make a copy of the yarn workspace packages instead of creating symlinks?
Or, is there another way to remove all of the unused code (e.g. the client code) so that my docker image isn't bloated?
You can use yarn-workspace-isolator to extract the package with its local dependencies to avoid publishing them to npm if you don't want to.
isolate-workspace -w my-package -o ~/dist/my-package
Now, as the doc saying:
You can simply run yarn install inside of ~/dist/my-package and yarn will
install all dependencies as if you had not used workspaces at all
without having to publish any workspace dependency.
Running yarn install in workspaces does the same thing inside any package or the root directory. It installs the modules for every package and symlinks them etc.
If you want to build a docker image for just the server you should only copy that package into the container and install that as an independent package.
If the server has a dependency on the shared lib, you could publish it to npm so it can fetch it too.

Does "yarn install" ignore what's in node_modules already?

When I run yarn install (or just yarn for short) and I don't have a yarn.lock file yet, will the result depend on what packages are already installed in my node_modules directory? Or will node_modules end up in the same state regardless of what's already in there?
In other words, do I need to run rm -rf node_modules "just in case" before running yarn, to make sure that I get the latest versions?
yarn seems to wipe node_modules, generate a lockfile, then download everything without lockfile for me (0.18.1).
If I then modify node_modules, further yarn calls don't do anything, but adding a dependency introducing a change to the lockfile then calls it to wipe my node_modules again.
(I recall reading a yarn github thread about how wiping node_modules for any lockfile changes being the normal behavior, but now I don't know how to find that comment)

Resources