12

I'm trying to set up a Haskell project with Stack. I have created a project: stack new project1 and added the suggested dependency (acme-missile) just to see how it works.

extra-deps:
- acme-missiles-0.3

But when I try to invoke launchMissile in the Main it won't work. I get

Error:(3, 1)     Could not find module ‘Acme.Missiles’
    Use -v to see a list of the files searched for.
  |
3 | import Acme.Missiles
  | ^^^^^^^^^^^^^^^^^^^^

What is the problem? What am I missing?

EDIT

When I run stack solver I get this:

Using configuration file: stack.yaml
Using cabal packages:
- ./


The following changes will be made to stack.yaml:
* Dependencies to be deleted
    extra-deps:
    - acme-missiles-0.3

To automatically update stack.yaml, rerun with '--update-config'

Isn't that strange? Like it thinks my dependency is not needed?

godzsa
  • 2,105
  • 4
  • 34
  • 56

1 Answers1

15

You'll need to add the dependency to project1.cabal as well:

build-depends:
    base >=4.7 && <5
  , project1
  , acme-missiles

Alternatively, on newer versions of Stack, it looks like you should use package.yaml instead:

dependencies:
- base >= 4.7 && < 5
- acme-missiles

I can't say that I have deep knowledge of how this works, but if I understand it correctly, the main file where you're supposed to add dependencies is in the .cabal or package.yaml file. The extra-deps field in stack.yaml is where you can indicate if you have dependencies that deviate from the LTS that you currently use.

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
  • 1
    Thank you, that solved my issue. If you use newer Stack you should not modify the `.cabal` file by hand, Stack generates it, but it is necessary to add it to the dependencies :) – godzsa Jan 14 '18 at 16:01