Yarn 3 nodeLinker: node-modules - yarnpkg

Why does yarn create a ".yarn/cache" directory when use node-modules ?.
My .yarnrc.yml
nodeLinker: node-modules

Related

How to run tsc --init in a subdirectory without installing it globally

I have the following directory structure:
.
|-- package.json
|-- tsconfig.json
|-- src/
|--subproject
I want to run tsc --init in src/subproject, but I don't want to install tsc globally. Running yarn --cwd src/subproject tsc --init doesn't work; it seems to be equivalent to cd src/subproject; yarn tsc --init which will still run tsc in the root directory.
Is it even possible to run tsc in this way?
This appears to work: cd src/subproject; npx tsc --init. But it doesn't seem like a good idea to imbed one project within an other.

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

ESLint couldn't find the plugin "eslint-plugin-react"

I work in sublime-text 3 with the following project structure:
workdir
--root-project-dirictory
---- src
---- eslint.yml
--project.sublime-project
The problem is this: ESLint is looking for the eslint-plugin-react plugin in workdir and not in the root-project-dirictory.
As a result I get an error:
ESLint couldn't find the plugin "eslint-plugin-react".
(The package "eslint-plugin-react" was not found when loaded as a Node module from the directory "/.../workdir".)
...
The plugin "eslint-plugin-react" was referenced from the config file in "root-project-dirictory / .eslintrc.yml".
The problem is this: ESLint is looking for the eslint-plugin-react plugin in workdir and not in the root-project-dirictory.
If eslint-plugin-react is included in the root working directory then it should be installed in the root and you can then extend the sub config from the root.
Until now, I have not found a solution to this problem without changing the structure of the working directory.
As a solution, I use the following:
create an empty sublime-text project
add one by one folder to the project, such as "src", "app" ...
if files are needed in --root-project-dirictory, then add it, but I'm working on the application in separate sublime-text folders of the project
I faced the same issue and found the main reason and how to fix:
npx eslint . --fix
Oops! Something went wrong! :(
ESLint: 6.1.0.
ESLint couldn't find the plugin "eslint-plugin-import".
or this error
Error: Cannot find module 'eslint-config-airbnb'
To fix it run this:
$ rm -rf node_modules
$ npm install eslint --save
$ npm install eslint-config-airbnb-base --save
$ npm install eslint-plugin-markdown --save
$ npm install eslint-plugin-import --save
(install all other plugins)
$ npm i
$ npx eslint --version
(should be less than 7)
Now, it works:
npx eslint . --fix
Reason:
It seems if libs listed under dev reps, ESLint got updated automatically to 7.0 which is not ready yet. As you can see we had the same error before on version 6.
For me, the issue was that I was using eslint globally which does not have that plugin. I used the command npx eslint ... then it worked normally.
In my case I did find a .eslintrc.json file in the Project Parent folder. After deleting it everything went back to normal.

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.

Yarn - remove package best practices

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

Resources