0
Fork 0
mirror of https://github.com/verdaccio/verdaccio.git synced 2024-12-16 21:56:25 -05:00
verdaccio/website/versioned_docs/version-6.x/setup-yarn.md

78 lines
2.1 KiB
Markdown
Raw Normal View History

2023-10-10 11:54:30 -05:00
---
id: setup-yarn
title: 'yarn'
---
# yarn {#yarn}
2024-09-26 14:05:10 -05:00
#### `yarn` classic (1.x) {#yarn-classic-1x}
2023-10-10 11:54:30 -05:00
2024-09-26 14:05:10 -05:00
> Be aware `.npmrc` file configuration is recognized by yarn classic.
2023-10-10 11:54:30 -05:00
2024-09-26 14:05:10 -05:00
The classic version is able to regonise the `.npmrc` file, but also provides their own configuration file named `.yarnrc`.
2023-10-10 11:54:30 -05:00
To set up a registry, create a file and define a registry.
```
// .yarnrc
registry "http://localhost:4873"
```
2024-09-26 14:05:10 -05:00
`yarn@1.x` by default does not send the token on every request unless is being opt-in manually, this might causes `403 error` if you have protected the access of your packages.
To change this behaviour enable `always-auth` in your configuration :
2023-10-10 11:54:30 -05:00
```
2024-09-26 14:05:10 -05:00
always-auth=true
2023-10-10 11:54:30 -05:00
```
2024-09-26 14:05:10 -05:00
or running
2023-10-10 11:54:30 -05:00
2024-09-26 14:05:10 -05:00
```
npm config set always-auth true
```
2023-10-10 11:54:30 -05:00
2024-09-26 14:05:10 -05:00
#### `yarn` modern (>=2.x) {#yarn-modern-2x}
> Yarn modern does not recognize `--registry` or `.npmrc` file anymore.
2023-10-10 11:54:30 -05:00
For defining a registry you must use the `.yarnrc.yml` located in the root of your project or global configuration.
When you publish a package the `npmRegistryServer` must be used. Keep in mind the `publishConfig.registry` in the `package.json` will override this configuration.
```yaml
// .yarnrc.yml
npmRegistryServer: "http://localhost:4873"
unsafeHttpWhitelist:
- localhost
```
> `unsafeHttpWhitelist` is only need it if you don't use `https` with a valid certificate.
Using scopes is also possible and more segmented, you can define a token peer scope if is required.
```
npmRegistries:
"https://registry.myverdaccio.org":
npmAlwaysAuth: true
npmAuthToken: <TOKEN>
npmScopes:
my-company:
npmRegistryServer: https://registry.myverdaccio.org
npmPublishRegistry: https://registry.myverdaccio.org
```
for logging via CLi use:
```
yarn npm login --scope my-company
```
2024-09-26 14:05:10 -05:00
## Troubleshooting {#troubleshooting}
### Known issues
- `yarn npm login` issues, read [verdaccio#1737](https://github.com/verdaccio/verdaccio/issues/1737) or [yarn-berry#1848](https://github.com/yarnpkg/berry/pull/1848).
- `yarn npm publish` does not send README, read [verdaccio#1905](https://github.com/verdaccio/verdaccio/issues/1905) or [yarn-berry#1702](https://github.com/yarnpkg/berry/issues/1702).