purescript-contrib/purescript-affjax

Cannot import value unsafeCoerceEff from module Control.Monad.Eff.Unsafe

Closed this issue · 6 comments

This is what I did:

npm install -g pulp
mkdir gh
cd gh
pulp init
echo "module Main where" > src/Main.purs
bower install purescript-affjax
npm install xhr2
pulp build

And I got the following errors:

▸ pulp build
* Building project in /Users/leo/pure/gh
Error 1 of 2:

  in module Control.Monad.Eff.Ref.Unsafe
  at /Users/leo/pure/gh/bower_components/purescript-refs/src/Control/Monad/Eff/Ref/Unsafe.purs line 7, column 34 - line 7, column 49

    Cannot import value unsafeCoerceEff from module Control.Monad.Eff.Unsafe
    It either does not exist or the module does not export it.


  See https://github.com/purescript/purescript/wiki/Error-Code-UnknownImport for more information,
  or to contribute content related to this error.

Error 2 of 2:

  in module Control.Monad.Rec.Class
  at /Users/leo/pure/gh/bower_components/purescript-tailrec/src/Control/Monad/Rec/Class.purs line 128, column 8 - line 128, column 31

    Unknown value U.unsafeCoerceEff


  See https://github.com/purescript/purescript/wiki/Error-Code-UnknownName for more information,
  or to contribute content related to this error.


Compiling Main
Compiling Control.Monad.Eff.Ref.Unsafe
Compiling Control.Monad.Rec.Class
* ERROR: Subcommand terminated with exit code 1


I tried

rm -rf bower_components/
bower install purescript-affjax

But didn't work.

My environment:

~/pure/gh
▸ node -v
v6.9.1

~/pure/gh
▸ pulp -v
Pulp version 9.0.1
psc version 0.10.1 using /Users/leo/.nvm/versions/node/v6.9.1/bin/psc

I'm still new to purescript, did I miss anything?

garyb commented

Looks like pulp hasn't been released with the updates for PureScript 0.10 yet, so pulp init will be generating a bower.json with outdated dependencies. It should have:

  "dependencies": {
    "purescript-console": "^2.0.0"
  },
  "devDependencies": {
    "purescript-psci-support": "^2.0.0"
  }

Rather than 1.0.0 for those. If you update that yourself, then rm -rf bower_components you should then be able to bower install purescript-affjax and things will work out.

garyb commented

Pulp has now been updated (to 9.1.0) and will now generate an up to date initial bower.json with pulp init.

Thanks @garyb. Yes, It worked.

However, as a developer, the fix is a bit magical to me :)

The Error messages were from modules purescript-refs and purescript-tailrec. But the fix was to update the version of purescript-console and purescript-psci-support, which looks like has nothing to do with that two modules. It would be difficult for developer to think of the fix if the Error messages are not related.

The problem looks like is the compatibility between modules. I think as a module, purescript-affjax should claim what are the dependencies, and what's the versions that would work. And the test cases will prove that.

In package.json, it claims that it would work with pulp 9.0.1, but I tried, it didn't work.

As a new comer, I'm a bit worried about the compatibility between modules. If say in the future I introduce a new module, and pulp build might throw some Error that I will have no idea which module is actually using the wrong version.

Since I'm new here, I'm wondering if there is any best practice to avoid this kind of mistake? Or any steps to follow to debug the kind of problems?

Thanks

garyb commented

The Error messages were from modules purescript-refs and purescript-tailrec. But the fix was to update the version of purescript-console and purescript-psci-support, which looks like has nothing to do with that two modules. It would be difficult for developer to think of the fix if the Error messages are not related.

Did bower ask you to choose between versions because of a conflict when you tried to bower install purescript-affjax? Generally when that occurs it's a clue that things aren't going to compile together if you force a resolution - it's not always the case, but usually is.

In package.json, it claims that it would work with pulp 9.0.1, but I tried, it didn't work.

pulp 9.0.1 is indeed able to build the affjax project, and would have built yours also after updating the dependencies - the only change between 9.0.1 and 9.1.0 is the template file was updated when you run a pulp init.

Since I'm new here, I'm wondering if there is any best practice to avoid this kind of mistake?

Not really, this one is definitely on us! It's a few weeks since most of the libraries were updated for PureScript 0.10, but pulp was lagging behind a little.

The only thing I would say is that point about bower - if it ever asks you to resolve a dependency conflict then situations like that you encountered are likely to arise. We're working on a real package manager for PureScript that should help avoid these situations in the future too.

Did bower ask you to choose between versions because of a conflict when you tried to bower install purescript-affjax?

Yes it did.

Thanks for explaining this to me. I remembered I encountered the same problem when purescript 0.8 was just out. It's a bit frustrating for me to deal with the bower dependency conflicts, and I didn't continue at that time :p

It's great to know that you guys are working on a real package manager for PS 👍

garyb commented

It's a bit frustrating for me to deal with the bower dependency conflicts, and I didn't continue at that time :p

Yeah, I can understand that! It's been a bit of a mess after the last few major releases... we're trying to get better at it, and psc-package will hopefully make it entirely painless in the long run (wishful thinking perhaps 😉).