Fix #996. Check module path is valid before adding it to .