diff --git a/src/main/java/com/hubspot/jinjava/lib/tag/ImportTag.java b/src/main/java/com/hubspot/jinjava/lib/tag/ImportTag.java
index <HASH>..<HASH> 100644
--- a/src/main/java/com/hubspot/jinjava/lib/tag/ImportTag.java
+++ b/src/main/java/com/hubspot/jinjava/lib/tag/ImportTag.java
@@ -219,6 +219,13 @@ public class ImportTag implements Tag {
     JinjavaInterpreter interpreter
   ) {
     String path = StringUtils.trimToEmpty(helper.get(0));
+    String templateFile = interpreter.resolveString(
+      path,
+      tagToken.getLineNumber(),
+      tagToken.getStartPosition()
+    );
+    templateFile = interpreter.resolveResourceLocation(templateFile);
+    interpreter.getContext().addDependency("coded_files", templateFile);
     try {
       interpreter
         .getContext()
@@ -241,14 +248,6 @@ public class ImportTag implements Tag {
       );
       return Optional.empty();
     }
-
-    String templateFile = interpreter.resolveString(
-      path,
-      tagToken.getLineNumber(),
-      tagToken.getStartPosition()
-    );
-    templateFile = interpreter.resolveResourceLocation(templateFile);
-    interpreter.getContext().addDependency("coded_files", templateFile);
     return Optional.of(templateFile);
   }
Resolve import path before adding it to the path stack