physics.raycast nullReferenceException

i get this error when using this raycast code:

var back = transform.TransformDirection (Vector3.back);
var hit : RaycastHit;
     if (Physics.Raycast (transform.position, back, 10)) {
     print (hit.collider.tag);

the error specifically is :

NullReferenceException: Object reference not set to an instance of an object.

the object it hits is a prefab which has been instantiated and has a box collider.

Your hit variable isn’t set to anything. You need to call one of the Physics.Raycast methods that returns the hit info.