Common issues and solutions to help you resolve problems quickly.
Error: Cannot resolve module '@rifrocket/fabricjs-design-tool'
# Check if package is installed
npm list @rifrocket/fabricjs-design-tool
# Reinstall if missing
npm install @rifrocket/fabricjs-design-tool
# Clear npm cache
npm cache clean --force
# Remove node_modules and reinstall
rm -rf node_modules package-lock.json
npm install
Warning: fabric@UNMET PEER DEPENDENCY
# Install required peer dependencies
npm install fabric react react-dom
# For TypeScript projects
npm install --save-dev @types/fabric
Canvas appears blank or shapes don't show up
// ❌ Wrong - element might not exist yet
const canvas = new fabric.Canvas('my-canvas');
// ✅ Correct - wait for DOM
useEffect(() => {
const canvas = new fabric.Canvas('my-canvas');
// ... rest of setup
}, []);
// Always call renderAll after adding objects
canvas.add(rectangle);
canvas.add(circle);
canvas.renderAll(); // ← Important!
Canvas appears too small or doesn't fit container
// Set canvas dimensions properly
canvas.setDimensions({
width: container.clientWidth,
height: container.clientHeight
});
// For responsive canvas
function resizeCanvas() {
const container = canvas.getElement().parentElement;
canvas.setDimensions({
width: container.clientWidth,
height: container.clientHeight
});
}
window.addEventListener('resize', resizeCanvas);
Can't select or interact with canvas objects
// Check canvas selection is enabled
canvas.selection = true;
// Check object selectability
object.selectable = true;
object.evented = true;
// For text objects
textObject.editable = true;
Canvas becomes sluggish with many objects
// Enable object caching for static objects
object.set({
objectCaching: true,
statefullCache: true
});
// Disable features you don't need
canvas.set({
skipTargetFind: true, // For non-interactive canvases
renderOnAddRemove: false // Manually control rendering
});
// Batch operations
canvas.renderOnAddRemove = false;
canvas.add(obj1, obj2, obj3);
canvas.renderOnAddRemove = true;
canvas.renderAll();
Application memory usage keeps growing
// Properly dispose canvas
useEffect(() => {
const canvas = new fabric.Canvas('my-canvas');
return () => {
canvas.dispose(); // Clean up event listeners
};
}, []);
// Remove event listeners
canvas.off('mouse:down', handler);
// Clear canvas properly
canvas.clear();
canvas.renderAll();
Error: Property 'canvas' does not exist on type
# Install type definitions
npm install --save-dev @types/fabric
# Add to tsconfig.json
{
"compilerOptions": {
"types": ["fabric"]
}
}
TypeScript can't find module declarations
// Create a types.d.ts file in your src folder
declare module '@rifrocket/fabricjs-design-tool' {
export * from '@rifrocket/fabricjs-design-tool/lib/core';
}
declare module '@rifrocket/fabricjs-design-tool/ui' {
export * from '@rifrocket/fabricjs-design-tool/lib/ui';
}
Canvas gets recreated on every render
// Use useRef to maintain canvas instance
const canvasRef = useRef(null);
const [canvas, setCanvas] = useState(null);
useEffect(() => {
if (canvasRef.current && !canvas) {
const fabricCanvas = new fabric.Canvas(canvasRef.current);
setCanvas(fabricCanvas);
}
}, [canvas]);
// Don't recreate canvas in render
return <canvas ref={canvasRef} />;
React Hook useEffect has missing dependencies
// Use useCallback for event handlers
const handleObjectModified = useCallback((e) => {
// Handle modification
}, [/* dependencies */]);
useEffect(() => {
if (!canvas) return;
canvas.on('object:modified', handleObjectModified);
return () => {
canvas.off('object:modified', handleObjectModified);
};
}, [canvas, handleObjectModified]);
Fabric.js is not properly imported or loaded
// ✅ Correct import
import { fabric } from 'fabric';
// ✅ Or for older versions
import * as fabric from 'fabric';
Canvas is null when trying to add objects
// ✅ Always check canvas exists
if (canvas) {
canvas.add(object);
}
// ✅ Or use optional chaining
canvas?.add(object);
Using wrong Fabric.js version or method
// ✅ Check Fabric.js version compatibility
npm list fabric
// ✅ Use correct method name
const bounds = object.getBoundingRect(); // v5+
// or
const bounds = object.getBounds(); // older versions
When reporting a bug, please include: