Overview
Thepm link command creates symbolic links between local packages, allowing you to develop and test packages together without publishing them.
Syntax
Arguments
string[]
Arguments passed directly to your package manager’s link command
Examples
Create Global Link
In the package you want to link:Output
Link to Another Project
In the project that needs the package:Output
Link with Path
Link directly using a file path:Output
Use Cases
Local Development
Develop a library and application together:1
Create Global Link
In your library project:
2
Link in Application
In your application project:
3
Develop and Test
Changes in
ui-library are immediately reflected in web-appTesting Unpublished Changes
Test changes before publishing to npm:Monorepo Alternative
While monorepos handle this automatically,pm link is useful for:
- Cross-monorepo development
- Testing packages outside their monorepo
- Temporary connections between projects
How It Works
Fromsrc/commands/link.ts:10-17:
- Detects your package manager
- Passes all arguments to the native link command
- Creates symbolic links in node_modules
Package Manager Behavior
pnpm requires
--global flag for creating global links. Better PM passes this through automatically.Verification
Check if a package is linked:Output
-> indicates a symbolic link.
Troubleshooting
Link Not Working
If changes aren’t reflected:-
Rebuild the linked package:
-
Check if link exists:
-
Re-create the link:
TypeScript Issues
For TypeScript projects, you may need:tsconfig.json
Build Watch Mode
For real-time changes, run the linked package in watch mode:Best Practices
- Document links - Keep track of which packages are linked
- Use watch mode - Run builds in watch mode for instant updates
- Unlink after testing - Remove links when done to avoid confusion
- Consider alternatives - For monorepos, use workspace features instead
Related Commands
- pm unlink - Remove symbolic links
- pm ls - List dependencies and check links
- pm install - Install dependencies normally