prevent cannot set property of undefined error

the opts object should be defined before the error checking line.