Yarn - remove package best practices - yarnpkg

If you want to remove a package using Yarn should you:
run yarn remove [package]
or
delete it from package.json and run yarn install
Do both work the same? Will #2 update yarn.lock?

If you run yarn remove [package] it will remove the package from node_modules and also from the yarn.lock file.
If you manually delete from package.json and then run yarn install, the deleted package is not installed and the yarn.lock file is not updated.

When you remove with Yarn by running the first approach (#1).
yarn remove [package]
Both your entries from lockfile and package.json are removed. Look out for this message in the terminal.
$ yarn remove x2js
yarn remove v0.27.5
[1/2] Removing module x2js...
[2/2] Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
Done in 2.34s.
The new file won't have the package.
If you follow the second (#2) approach and delete it from package.json and run:
yarn install
There will we no effect on your lockfile.
So it is better to remove packages using the first approach (#1).
If you have deleted some package(s) directly from package.json and don't know what was there then your lockfile is not up to date.
I would suggest you delete the yarn.lock file . and then run yarn install. This way, you will get an updated yarn.lock file.

Automatic Deletion
yarn remove <package-name>
Manual Deletion
In case of manual removal of package from package.json ,
delete yarn.lock file and run yarn install

Best way to remove any package is
yarn remove "your package name"
Your package name should be same as your package.json file

Related

`pnpm install` Usage Error: This project is configured to use yarn

I am trying to migrate from yarn to pnpm. I ran pnpm install. It instantly failed and printed to the console:
Usage Error: This project is configured to use yarn
$ pnpm ...
I tried removing (renaming actually) yarn.lock and node_modules but to no avail. How to solve this?
I figured out that it's because of:
{
// ...
"packageManager": "yarn#..."
// ...
}
removing (or changing it to pnpm) would solve the issue. Additionally, yarn.lock existence doesn't have do with issue.

Update yarn.lock after removing a workspace

Suppose I have a monorepo using the standard workspace structure:
monorepo
|- package.json
|- yarn.lock
|- packages
|- package_a
|- package_b
I want to completely get rid of package_a while also updating the yarn.lock accordingly.
The following doesn't update the lockfile:
$ rm -rf packages/package_a
$ yarn install
Running this in the root of the monorepo doesn't work either:
$ yarn remove -W package_a
error This module isn't specified in a package.json file.
This does work, but bumps all packages where the range allows which is not desired.
$ rm -rf packages/package_a
$ yarn upgrade
How can I accomplish this?
I may misunderstand your question... But it appears that you need to include each package in your package.json as mentioned with each workspace here: https://classic.yarnpkg.com/en/docs/workspaces/.
Needed in package.json:
{
"private": true,
"packages": ["package_a", "package_b"]
}
I'm guessing this is why you are getting the error error This module isn't specified in a package.json file. when attempting yarn remove -W package_a. When it is included in the package.json then just yarn remove package_a this will also update your yarn.lock automatically.
https://classic.yarnpkg.com/en/docs/cli/remove

graphql-codegen not running with config file

In my package.json file I've got script entry that runs graphql-codegen but it complains that the --config argument is invalid:
$> yarn gen
yarn run v1.21.1
$ graphql-codegen --config codegen.yml
Error: Unknown argument: config
...
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Since I believe the default file name is codegen.yml anyway, I try to run it with out that argument and nothing gets generated:
$> yarn graphql-codegen
yarn run v1.21.1
$ /home/aaron/projects/my_app/node_modules/.bin/graphql-codegen
Done in 0.17s.
Any ideas?
for me this solved the issue
Yarn
yarn add -D #graphql-codegen/cli
npm
npm i -D #graphql-codegen/cli
installation guide doc
Ok, I'm not sure exactly what I did to fix this. I believe that I had also installed graphql-codegen globally and tried to uninstall it with sudo npm uninstall graphql-codegen which removed a bunch of packages but the executable still exists:
$>which graphql-codegen
/usr/bin/graphql-codegen
However I decided to run yarn graphql-codegen init on a whim to see if init was valid and because I couldn't remember if I hadn't tried that already. I got the set up questions like normal so I ctrl+C'ed and just ran yarn graphql-codegen and it worked! Then I ran yarn graphql-codegen --watch to test that it took options and that also worked.
If anyone gets this issue, I hope these tips help you.
Try it: rm -rf ./node_modules && npm install
rm http://manpages.ubuntu.com/manpages/trusty/man1/rm.1.html
remove files or directories
-f, --force ignore nonexistent files and arguments, never prompt
-r, -R, --recursive remove directories and their contents recursively
node_modules https://docs.npmjs.com/cli/v7/configuring-npm/folders
You can think of the node_modules folder like a cache
for the external modules that your project depends upon. When you npm
install them, they are downloaded from the web and copied into the
node_modules folder and nodejs is trained to look for them there when
you import them (without a specific path).
npm install https://docs.npmjs.com/cli/install/
This command installs a package and any packages that it depends on.
If the package has a package-lock, or an npm shrinkwrap file, or a
yarn lock file, the installation of dependencies will be driven by
that, respecting the following order of precedence:
npm-shrinkwrap.json
package-lock.json
yarn.lock
Might also be that you have apollo's graphql-codegen package installed, which also exposes a binary called graphql-codegen, which accepts args schema and output, but not config.
For me the solution was to install #graphql-codegen/cli.
graphql.config.yml
schema: http://localhost:8081/graphql
extensions:
codegen:
generates:
./schema.graphql:
- schema-ast
package.json
{
"codegen": "graphql codegen --config graphql.config.yml"
}
I've fixed the problem by using graphql-code-generator instead:
"scripts": {
"graphql:generate": "graphql-code-generator"
}

Lerna, what's the opposite of 'yarn run lerna add component-a'

With Lerna to add a package to all other package file I can use -
yarn run lerna add component-a
With this I see the item added to all package files in my overall repo.
If I use
yarn run lerna clean component-a
the output suggests its remove the component from the node_modules but it still exists inside the package files that were added via the add command.
So what will reverse the add command fully.

How do I install vuetify directly from github?

When I try with
npm install vuetifyjs/vuetify#v1.5.2
I get "Cannot find package".
UPDATE:
There is a packages folder under which there is a vuetify directory.
I tried npm installing that folder. Everything appeared to go well until I started the dev server.
Now in the console log I see:
[Vuetify] Multiple instances of Vue detected
Seems to be related to https://github.com/vuetifyjs/vuetify/issues/4068 but I cannot tell what the solution is at this point.
I had the same issue to use my own version of Vuetify, waiting for my pull request being accepted.
Here what I did:
I build the vuetify project with my fix.
yarn
yarn build
Then I took the content of 'packages/vuetify' and put it in a new git repository. I remove the .gitignore to be able to commit built files (/es5, /lib, /lib-temp, /dist)
Finally I add this git repository to my project to replace my vuetify version:
npm install git+https://gitlab.com/GITLABUSERNAME/REPOSITORYNAME.git
Looking at the package.json file, the package doesn't have a name property, which it would need to have for you to be able to install it from GitHub.
So the short answer is that you can't install vuetify directly from GitHub via npm.
However, you can install it directly from npm:
npm install vuetify#1.5.2
You can't install vuetify directly from GitHub but you can edit code in 1 component node_modules/vuetify/lib/components/VSlider/VSlider.js Then, you install patch-package and execute path package vuetify Delete node modules and execute yarn to create new node modules Last, yarn serve, you see your code is work
https://www.npmjs.com/package/patch-package

Resources