Common Issues
This guide covers common problems you might encounter when using the Create Zustand CLI and how to resolve them.npm link Issues
Command Not Found After npm link
If you runnpm link but the create-zustand-store command is not recognized:
Solution:
.bashrc or .zshrc:
npm link Fails with Symlink Error
On some systems, npm link may fail due to symlink permission issues. Solution:-
Try running with sudo (Linux/macOS):
-
Or change npm’s default directory (preferred):
Permission Errors
EACCES: permission denied
You may encounter permission errors when installing global packages or running npm link.Never use sudo with npm unless absolutely necessary. Instead, configure npm to use a directory you own.
-
Create a directory for global installations:
-
Add the directory to your PATH in
~/.bashrcor~/.zshrc: -
Reload your shell configuration:
Cannot Write to Store Directory
If you get a permission error when the CLI tries to create the store directory: Solution:-
Check the permissions of your project directory:
-
Ensure you own the directory:
Missing Dependencies
Module Not Found Errors
If you see errors likeCannot find module 'commander' or similar:
Solution:
chalk(^5.3.0)commander(^8.0.0)fs-extra(^10.0.0)inquirer(^8.0.0)zustand(^4.5.2)
Zustand Not Installed in Project
The CLI attempts to auto-install Zustand, but this may fail if: Solution:-
Ensure your project has a
package.json: -
Manually install Zustand:
Configuration Issues
Invalid JSON in Initial State
If you provide invalid JSON for the initial state, the CLI will exit with an error. Solution: Ensure your initial state is valid JSON:Configuration File Not Loading
If your saved configuration inzustand-store-config.json is not being loaded:
Solution:
-
Check that the file exists in your current working directory:
-
Verify the JSON is valid:
-
If corrupted, delete and recreate:
Template Issues
Template File Not Found
If you seeTemplate file not found error:
Solution:
Ensure the templates directory exists with all required files:
store.jsstore.tsstore-persist.jsstore-persist.ts
TypeScript Issues
Type Errors in Generated Store
If you encounter TypeScript errors in the generated store file: Solution:-
Check that TypeScript is installed in your project:
- Manually update the generated types in your store file if needed
Runtime Errors
Store Not Persisting Data
If you enabled persistence but data isn’t being saved: Solution:- Verify you’re in a browser environment (persistence uses localStorage)
- Check browser console for storage errors
- Ensure your store name is unique
- Clear localStorage and test again:
Actions Not Updating State
If your actions aren’t working as expected:The CLI generates empty action implementations. You need to add your own logic inside each action.
Getting Help
If you’re still experiencing issues:- Check the GitHub repository for known issues
- Review the FAQ for common questions
- Open an issue with:
- Your environment (OS, Node version, npm version)
- Complete error message
- Steps to reproduce