New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have "stack script" set import search path #3377 #4538

merged 1 commit into from Jan 26, 2019


None yet
4 participants
Copy link

mgsloan commented Jan 25, 2019

  • Any changes that could be relevant to users have been recorded in the
  • The documentation has been updated, if necessary.

This issue was brought to my attention by . The primary problem is that stack scripts can only import modules if the script is run from the same directory as the modules. However, I realized that this implies a gnarlier issue, which is that since -i isn't being passed to runghc, it will use the work dir as a search dir for imports.

This also addresses part of the problem described in #3377 , which was a difference in how imports are treated when --compile is used.

Here's a concrete example. The contents of ~/tmp/hmm.hs is

#!/usr/bin/env stack
-- stack --resolver lts-13.0 script

import Yargh

main :: IO ()
main = yargh

The contents of ~/tmp/Yargh.hs is

module Yargh where

yargh :: IO ()
yargh = putStrLn "works!"

The contents of ~/Yargh.hs is

module Yargh where

yargh :: IO ()
yargh = putStrLn "YARGH, broken!

Check out what happens when I run the script from different directories:

mgsloan@treetop:~/tmp$ ./hmm.hs                                                                               
mgsloan@treetop:~/tmp$ cd ../                                                                                 
mgsloan@treetop:~$ ./tmp/hmm.hs                                                                               
YARGH, broken!      

This PR resolves the issue. After applying this patch, it behaves like this:

mgsloan@treetop:~/tmp$ ./hmm.hs                                                                               
mgsloan@treetop:~/tmp$ cd ../                                                                         
mgsloan@treetop:~$ ./tmp/hmm.hs                                                                               

@mgsloan mgsloan force-pushed the stack-script-import-search-path-3377 branch from dac3359 to ec2a139 Jan 25, 2019


qrilka approved these changes Jan 25, 2019


This comment has been minimized.

Copy link

rcook commented Jan 26, 2019


@mihaimaruseac mihaimaruseac merged commit 38ee7fe into master Jan 26, 2019

1 check passed

continuous-integration/appveyor/branch AppVeyor build succeeded

@mihaimaruseac mihaimaruseac deleted the stack-script-import-search-path-3377 branch Jan 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment