|
| 1 | +# Using `pnpm link` for Local SDK Testing |
| 2 | + |
| 3 | +[`pnpm link`](https://pnpm.io/cli/link) symlinks a local SDK package into a test project. Changes are available in the |
| 4 | +test project after a rebuild, without a publish step. For packages where linking causes problems (e.g. SvelteKit or |
| 5 | +Angular), use [`yalc`](./using-yalc.md) instead. |
| 6 | + |
| 7 | +## Building packages |
| 8 | + |
| 9 | +Build the SDK package and the packages it depends on. Run this in the root of the repo: |
| 10 | + |
| 11 | +```sh |
| 12 | +pnpm run build:dev:filter @sentry/node # or any other SDK package |
| 13 | +``` |
| 14 | + |
| 15 | +## Linking packages |
| 16 | + |
| 17 | +In your test project, run `pnpm link` with the path to the SDK package: |
| 18 | + |
| 19 | +```sh |
| 20 | +pnpm link /path/to/sentry-javascript/packages/node |
| 21 | +``` |
| 22 | + |
| 23 | +You only need to link the SDK package that your project imports. Its dependencies (e.g. `@sentry/core`) resolve from |
| 24 | +the monorepo, so they are also the local versions. If your project also imports a dependency directly (e.g. |
| 25 | +`@sentry/core`), that import still uses the version from the registry. Link that package too. |
| 26 | + |
| 27 | +`pnpm link` adds a `link:` override to the `pnpm-workspace.yaml` of your test project. If the file does not exist, |
| 28 | +`pnpm link` creates it. Do not commit this override. |
| 29 | + |
| 30 | +## Updating packages |
| 31 | + |
| 32 | +The link points to the `build/` folder of the package. After a code change, rebuild the package and restart your test |
| 33 | +project. You do not need to link again. |
| 34 | + |
| 35 | +```sh |
| 36 | +# in the package you changed, e.g. packages/core |
| 37 | +pnpm run build:transpile |
| 38 | +``` |
| 39 | + |
| 40 | +## Unlinking packages |
| 41 | + |
| 42 | +In your test project, run `pnpm unlink` with the package name. This removes the `link:` override and installs the |
| 43 | +registry version again. |
| 44 | + |
| 45 | +```sh |
| 46 | +pnpm unlink @sentry/node |
| 47 | +``` |
| 48 | + |
| 49 | +In pnpm 10, `pnpm unlink` shows "Nothing to unlink" and does not remove the override. Remove the override |
| 50 | +for the package from `pnpm-workspace.yaml` manually, then run `pnpm install`. |
| 51 | + |
| 52 | +## Troubleshooting |
| 53 | + |
| 54 | +### My test project still uses the registry version |
| 55 | + |
| 56 | +Make sure that `node_modules/@sentry/node` in your test project is a symlink to the monorepo: |
| 57 | + |
| 58 | +```sh |
| 59 | +ls -la node_modules/@sentry/node |
| 60 | +``` |
| 61 | + |
| 62 | +If you run Node.js or your bundler with `--preserve-symlinks`, dependencies resolve from the `node_modules` of your |
| 63 | +test project and not from the monorepo. Do not use this flag. |
| 64 | + |
| 65 | +### My test project uses Vite and I still don't see changes |
| 66 | + |
| 67 | +Vite pre-bundles and caches dependencies for dev builds. Run `vite dev --force` to clear the cache. |
0 commit comments