diff --git a/src/libs/qmljs/qmljsbind.cpp b/src/libs/qmljs/qmljsbind.cpp
index 61863631be8d8f2178aace0500c6f233dd0eddfe..cf042d9e538121a696845667de6fb0ea4eb87701 100644
--- a/src/libs/qmljs/qmljsbind.cpp
+++ b/src/libs/qmljs/qmljsbind.cpp
@@ -128,11 +128,11 @@ bool Bind::visit(UiImport *ast)
     ObjectValue *namespaceObject;
 
     if (ast->asToken.isValid()) { // with namespace we insert an object in the type env. to hold the imported types
-        namespaceObject = _interp->newObject(/*prototype */ 0);
-
         if (!ast->importId)
             return false; // this should never happen, but better be safe than sorry
 
+        namespaceObject = _interp->newObject(/*prototype */ 0);
+
         _typeEnvironment->setProperty(ast->importId->asString(), namespaceObject);
 
     } else { // without namespace we insert all types directly into the type env.