diff --git a/haste-compiler.cabal b/haste-compiler.cabal
--- a/haste-compiler.cabal
+++ b/haste-compiler.cabal
@@ -1,5 +1,5 @@
 Name:           haste-compiler
-Version:        0.5.1.0
+Version:        0.5.1.1
 License:        BSD3
 License-File:   LICENSE
 Synopsis:       Haskell To ECMAScript compiler
diff --git a/src/Haste/Module.hs b/src/Haste/Module.hs
--- a/src/Haste/Module.hs
+++ b/src/Haste/Module.hs
@@ -82,21 +82,29 @@
 #if __GLASGOW_HASKELL__ < 709
       return stdname
 #else
-      dirs <- filter (pkgid `isSuffixOf`) . map (basepath </>) <$> ls basepath
-      dirs' <- filterM isDirectory dirs
-      case dirs' of
-        ds | not (null ds) -> findLibFile ds
-           | otherwise     -> return stdname
+      mfile <- findLibFile [basepath]
+      case mfile of
+        Just f -> do
+          -- Lib file was found directly in basepath
+          return f
+        _         -> do
+          -- Lib file wasn't found directly in basepath, so let's try subdirs
+          contents <- ls basepath
+          let dirs = [basepath </> p | p <- contents, pkgid `isSuffixOf` p]
+          dirs' <- filterM isDirectory dirs
+          case dirs' of
+            ds | not (null ds) -> maybe stdname id <$> findLibFile ds
+               | otherwise     -> return stdname
 #endif
   where
     findLibFile (d:ds) = do
       fs <- map (d </>) . filter (libfilesuffix `isSuffixOf`) <$> ls d
       fs' <- filterM isFile fs
       case fs' of
-        (f:_) -> return f
+        (f:_) -> return (Just f)
         _     -> findLibFile ds
     findLibFile _ = do
-      return stdname
+      return Nothing
 
     -- Use this for non-special packages
     stdname = pkgid </> "libHS" ++ pkgid <.> "jslib"
diff --git a/src/Haste/Version.hs b/src/Haste/Version.hs
--- a/src/Haste/Version.hs
+++ b/src/Haste/Version.hs
@@ -12,7 +12,7 @@
 
 -- | Current Haste version.
 hasteVersion :: Version
-hasteVersion = Version [0,5,1,0] []
+hasteVersion = Version [0,5,1,1] []
 
 -- | Current Haste version as an Int. The format of this version number is
 --   MAJOR*10 000 + MINOR*100 + MICRO.
diff --git a/src/hastec.hs b/src/hastec.hs
--- a/src/hastec.hs
+++ b/src/hastec.hs
@@ -4,6 +4,8 @@
 import Language.Haskell.GHC.Simple
 #if __GLASGOW_HASKELL__ >= 710
 import Language.Haskell.GHC.Simple.PrimIface
+import Packages
+import PackageConfig
 #endif
 import GHC
 import Outputable (showPpr)
@@ -45,7 +47,11 @@
       Right (fs, mkConfig) -> do
         let ghcconfig = mkGhcCfg fs args
         (dfs, _) <- getDynFlagsForConfig ghcconfig
-        let cfg = mkLinkerCfg dfs . setShowOutputable dfs $ mkConfig def
+        extralibdirs <- getExtraLibDirs dfs
+        putStrLn $ "EXTRALIBDIRS: " ++ show extralibdirs
+        let cfg = mkLinkerCfg dfs extralibdirs
+                . setShowOutputable dfs
+                $ mkConfig def
         res <- compileFold ghcconfig (compJS cfg) ([], []) []
         case res of
           Failure _ _         -> do
@@ -56,6 +62,12 @@
                 then buildJSLib prof cfg (fst $ head targets) mods
                 else mapM_ (uncurry $ linkAndMinify cfg) targets
   where
+#if __GLASGOW_HASKELL__ >= 710
+    getExtraLibDirs = fmap (concatMap libraryDirs) . readPackageConfigs
+#else
+    getExtraLibDirs = const (return [])
+#endif
+
     dotToSlash '.' = '/'
     dotToSlash c   = c
 
@@ -102,9 +114,10 @@
         , cfgCustomPrimIface = Just (primOpInfo, primOpStrictness)
 #endif
       }
-    mkLinkerCfg dfs cfg = cfg {
+    mkLinkerCfg dfs extralibdirs cfg = cfg {
         mainMod = Just (pkgKeyString $ modulePkgKey (mainModIs dfs),
-                        moduleNameString $ moduleName (mainModIs dfs))
+                        moduleNameString $ moduleName (mainModIs dfs)),
+        libPaths = extralibdirs ++ libPaths cfg
       }
     setShowOutputable dfs cfg = cfg {showOutputable = showPpr dfs}
 
