Migration from nx-go
This guide helps you migrate from the original @nx-go/nx-go plugin to GoNx.
Overview of Changes
Section titled “Overview of Changes”GoNx is a modernized fork of nx-go with significant architectural changes:
Major Breaking Changes
Section titled “Major Breaking Changes”- Modern Nx-only: Requires Nx 21.x or later
- No project.json generation: Uses inferred tasks instead
- Changed command execution: Runs from project root instead of workspace root
- Removed go.work creation: Now opt-in via configuration
- Removed legacy generators:
convert-to-one-module
is no longer available
New Features
Section titled “New Features”- Inferred tasks: Automatic task detection and configuration
- Cacheable operations: All tasks are properly cached
- CreateNodesV2: Latest Nx project detection API
- Version Actions: Proper Go versioning with Nx Release
- Publish executor: Automated registry publishing
Migration Steps
Section titled “Migration Steps”Step 1: Prerequisites
Section titled “Step 1: Prerequisites”Before starting the migration:
- Upgrade Nx: Ensure you’re on Nx 21.x or later
- Update Go: Use a stable Go version (1.21+ recommended)
- Backup your workspace: Create a backup before making changes
- Review project structure: Understand your current setup
Step 2: Remove nx-go Plugin
Section titled “Step 2: Remove nx-go Plugin”Remove the original nx-go plugin:
npm uninstall @nx-go/nx-go# orpnpm remove @nx-go/nx-go# oryarn remove @nx-go/nx-go
Step 3: Install GoNx
Section titled “Step 3: Install GoNx”Install the GoNx plugin:
npm install @naxodev/gonx# orpnpm add @naxodev/gonx# oryarn add @naxodev/gonx
Step 4: Update Nx Configuration
Section titled “Step 4: Update Nx Configuration”Update your nx.json
to use GoNx:
{ "plugins": [ { "plugin": "@naxodev/gonx", "options": { "addGoDotWork": false } } ]}
Remove any nx-go specific configuration.
Step 5: Handle project.json Files
Section titled “Step 5: Handle project.json Files”GoNx uses inferred tasks, so you can remove project.json
files from your Go projects:
# Remove project.json files from Go projectsrm apps/my-go-app/project.jsonrm libs/my-go-lib/project.json
Step 6: Update Scripts and CI
Section titled “Step 6: Update Scripts and CI”Update any scripts or CI configurations that reference nx-go:
Package.json Scripts
Section titled “Package.json Scripts”{ "scripts": { "build:go": "nx run-many --target=build --projects=tag:go", "test:go": "nx run-many --target=test --projects=tag:go" }}
CI Configuration
Section titled “CI Configuration”Update your CI to use the new executors and ensure Go is available in the environment.
Common Migration Issues
Section titled “Common Migration Issues”Issue: Projects Named Changed
Section titled “Issue: Projects Named Changed”Problem: GoNx changed how project names are inferred
Solution: While nx-go uses the given name for the projects or the final segment of the path as the name, GoNx uses the entire path as the project name.
Although this can make commands longer, it has two main benefits:
- Removes the disambiguation name problem.
- Aligns perfectly with the Go standard for multi-module repository tag creation.
Issue: Tasks Not Found
Section titled “Issue: Tasks Not Found”Problem: Nx doesn’t recognize Go project tasks.
Solution:
- Ensure
go.mod
files exist in your Go projects - Clear Nx cache:
nx reset
- Verify plugin configuration in
nx.json
Issue: Project Graph Issues
Section titled “Issue: Project Graph Issues”Problem: Project dependencies aren’t detected correctly.
Solution:
- Ensure Go imports are correctly structured
- Use proper module paths
- Clear cache and regenerate:
nx reset && nx graph
Post-Migration Testing
Section titled “Post-Migration Testing”After migration, verify everything works:
1. Project Detection
Section titled “1. Project Detection”nx show projects
2. Task Execution
Section titled “2. Task Execution”nx build my-go-appnx test my-go-libnx lint my-go-app
3. Project Graph
Section titled “3. Project Graph”nx graph
4. Caching
Section titled “4. Caching”nx build my-go-appnx build my-go-app # Should use cache
Getting Help
Section titled “Getting Help”If you encounter issues during migration:
- Check documentation: Review GoNx documentation thoroughly
- Search issues: Look for similar issues on GitHub
- Join Discord: Get real-time help on our Discord server
- Create issue: Report bugs or request help on GitHub