Below is a set of recommendations that have helped others avoid the “Symlink path is the same as the target path” error with pnpm linking. Adjust these steps to match your repository names and package.json details:
1. Clear Existing Global Links
Sometimes a stale or conflicting global link causes the error. First, remove any existing global link for your package:
pnpm unlink --global @baseapp-frontend/authentication
Verify that the folder has been removed from your global pnpm links (typically under AppData/Local/pnpm/global/5/node_modules). If not, remove it manually.
2. Double-Check Package Naming & Paths
Make sure the package name given in the side repo’s package.json exactly matches what you use in the main repo’s link command. For example, if the package is named “@baseapp-frontend/authentication” in its package.json, then from the main repo use:
pnpm link --global @baseapp-frontend/authentication
Be aware that typos or mismatched names could inadvertently point pnpm to the same folder.
3. Resolve Peer Dependency Warnings
The warning about peerDependencies does not directly break the link but may cause issues later. If your package declares a peer dependency (like @baseapp-frontend/utils or a specific react version) that is expected to be provided by consumers, you might consider one of these options:
-
Install the peer dependencies in your main repo so that they are available.
-
If you want to completely ensure local resolution, reference the side package with the file protocol instead of a link. For example, update the dependency in your main repo’s package.json like this:
{
"dependencies": {
"@baseapp-frontend/authentication": "file:../side-repo/auth"
}
}
This can make sure that pnpm doesn’t mix global links with local workspace resolution for peer dependencies.
4. Use the Correct Sequence for Linking
The linking workflow should be:
-
In Side Repo:
Run the global link command in its package folder
cd side-repo/auth
pnpm link --global
Confirm that the global link has been created.
-
In Main Repo:
Link the package by referring to its global name:
cd main-repo
pnpm link --global @baseapp-frontend/authentication
Make sure you’re using the correct package name (as defined in its package.json).
5. Upgrade pnpm if Needed
If you’re on an older version of pnpm, consider upgrading. Some past issues with linking have been addressed in newer releases. Verify your pnpm version:
If it’s behind the latest release, upgrade by following the pnpm documentation.
Summary
- Remove any previously linked versions before re-linking.
- Verify that the package name and paths do not accidentally match their target path.
- Address the peer dependencies either by installing them or using a file reference.
- Ensure that you run commands in the correct order and upgrade pnpm if necessary.
These steps should eliminate the “symlink path is the same as the target path” error and stabilize the local linking between your Main Repo and Side Repo.