digitallyinduced / ihp

🔥 The fastest way to build type safe web apps. IHP is a new batteries-included web framework optimized for longterm productivity and programmer happiness
https://ihp.digitallyinduced.com/
MIT License
4.92k stars 195 forks source link

Could not find module `Network.Wai.Middleware.Cors' #958

Closed hendi closed 3 years ago

hendi commented 3 years ago

Following the "Running an application against a local copy of the framework" guide from CONTRIBUTING.md, :l Main fails with

...
[34 of 97] Compiling IHP.HSX.QQ       ( IHP/IHP/HSX/QQ.hs, interpreted )
[35 of 97] Compiling IHP.Fetch        ( IHP/IHP/Fetch.hs, interpreted )
[36 of 97] Compiling IHP.ValidationSupport.ValidateIsUnique ( IHP/IHP/ValidationSupport/ValidateIsUnique.hs, interpreted )
[37 of 97] Compiling IHP.ValidationSupport.ValidateCanView ( IHP/IHP/ValidationSupport/ValidateCanView.hs, interpreted )
[38 of 97] Compiling IHP.ValidationSupport ( IHP/IHP/ValidationSupport.hs, interpreted )
[39 of 97] Compiling IHP.FetchRelated ( IHP/IHP/FetchRelated.hs, interpreted )
[40 of 97] Compiling IHP.View.TimeAgo ( IHP/IHP/View/TimeAgo.hs, interpreted )
[41 of 97] Compiling IHP.View.Types   ( IHP/IHP/View/Types.hs, interpreted )
[42 of 97] Compiling IHP.View.CSSFramework ( IHP/IHP/View/CSSFramework.hs, interpreted )
[43 of 97] Compiling IHP.FrameworkConfig ( IHP/IHP/FrameworkConfig.hs, interpreted )

IHP/IHP/FrameworkConfig.hs:30:1: error:
    Could not find module `Network.Wai.Middleware.Cors'
    Perhaps you meant
      Network.Wai.Middleware.Gzip (from wai-extra-3.1.4.1)
      Network.Wai.Middleware.Jsonp (from wai-extra-3.1.4.1)
      Network.Wai.Middleware.Local (from wai-extra-3.1.4.1)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
   |
30 | import qualified Network.Wai.Middleware.Cors as Cors
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, 42 modules loaded.
mpscholten commented 3 years ago

The problem has also been reported on gitter. Likely a new nix-shell or make -B .envrc will fix the issue

hendi commented 3 years ago

Tried both, neither helped.

zmijunkie commented 3 years ago

Hi ! I worked around this by completely restarting from updating ihp-new and everything else . Then suddently it worked again. I am using debian10 and calling ./start a second time will bring back the error ....

CSchank commented 3 years ago

I'm having the same problem too :( Is it not picking up the new wai-cors dependency? Is there a way to force cabal to install it?

mpscholten commented 3 years ago

Inside the default.nix of your project, is there ihp = ./IHP; (line 4) or is it set to something like ihp = fetchgit ...?

CSchank commented 3 years ago

The line number doesn't quite line up, so let me post my entire default.nix file:

let
    ihp = builtins.fetchGit {
        url = "https://github.com/digitallyinduced/ihp.git";
        ref = "refs/tags/v0.11.0";
    };
    haskellEnv = import "${ihp}/NixSupport/default.nix" {
        ihp = ihp;
        haskellDeps = p: with p; [
            cabal-install
            base
            wai
            text
            hlint
            p.ihp
            haskell-to-elm
        ];
        otherDeps = p: with p; [
            # Native dependencies, e.g. imagemagick
        ];
        projectPath = ./.;
    };
in
    haskellEnv
mpscholten commented 3 years ago

Try this:

let
    ihp = ./IHP;
    haskellEnv = import "${ihp}/NixSupport/default.nix" {
        ihp = ihp;
        haskellDeps = p: with p; [
            cabal-install
            base
            wai
            text
            hlint
            p.ihp
            haskell-to-elm
        ];
        otherDeps = p: with p; [
            # Native dependencies, e.g. imagemagick
        ];
        projectPath = ./.;
    };
in
    haskellEnv

Otherwise it's using v0.11.0 for the dev environment (v0.11.0 doesn't contain the CORS middleware) :) With the ./IHP it's picking up your local files for the dev env.

CSchank commented 3 years ago

Hmm, I seem to run into an error when running make now. This could be my relative ignorance of nix...

✗ make -B .envrc
rm -f .envrc
echo "PATH_add $(nix-shell -j auto --cores 0 --pure --run 'printf %q $PATH')" > .envrc
error: getting status of '/nix/store/1k4dv4vyls5r5gs2ggc821razyiz1lxd-IHP/NixSupport/default.nix': No such file or directory
mpscholten commented 3 years ago

Do you have the ihp repo cloned inside your project directory at IHP?

CSchank commented 3 years ago

I actually have it symlinked to another folder, which had been working for me before.

mpscholten commented 3 years ago

Can you try to set it to the absolute path of where the symlink points to like ihp = /some/where/the/symlink/is/IHP;?

CSchank commented 3 years ago

Okay, I got it. At firs it didn't like that my symlink was relative. Then I got more errors when it was absolute. But setting it directly in default.nix seems to be the trick. I wonder why the relative symlink worked before and now didn't like it. Thanks for your help, sorry for all the minute questions!

mpscholten commented 3 years ago

I think the symlink problem is caused because nix copies the IHP version into the nix store and then the symlink is resolved from within there. Glad it's working now :)

zmijunkie commented 3 years ago

Hi ! I am trying to put a relative path ihp = ./IHP; into my default.nix and I am stopped now at

[ 23 of 174] Compiling IHP.IDE.SchemaDesigner.Parser ( IHP/IDE/SchemaDesigner/Parser.hs, dist/build/IHP/IDE/SchemaDesigner/Parser.o, dist/build/IHP/IDE/SchemaDesigner/Parser.dyn_o )
/nix/store/7d2w3lafm8cla7n6ii5jskhsnqg4zv3a-stdenv-linux/setup: line 1309: 27378 Killed                  ./Setup build
builder for '/nix/store/k113zrfjm930aabrbfyamwn6hjiwf720-ihp-v0.11.0.drv' failed with exit code 137
cannot build derivation '/nix/store/lyjjfbn9yzbfpcricd4bpyz09rjgnjnb-ghc-8.10.3-with-packages.drv': 1 dependencies couldn't be built
error: build of '/nix/store/lyjjfbn9yzbfpcricd4bpyz09rjgnjnb-ghc-8.10.3-with-packages.drv' failed
direnv: loading .envrc
./start: Zeile 17: RunDevServer: Kommando nicht gefunden.
direnv: loading .envrc

Still my workaround is to create everything new and run start or make only once. Weird - but maybe my understanding of the solution just isn't good enough ;-)

mpscholten commented 3 years ago

Is there some error above these lines? Otherwise the kill could indicate the system is out of memory. Do you have a swap set up?

zmijunkie commented 3 years ago

ah indeed I have got oom_reaper: reaped process 2032 (ghc), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB in my /var/log/messages

zmijunkie commented 3 years ago

Just increased RAM permissions to 10G on my development server and it works !

CSchank commented 3 years ago

Seems like 16gb is nothing these days.........

mpscholten commented 3 years ago

I run on 64 GB 😄

mpscholten commented 3 years ago

Is this problem still happening or can we close this one? :)

hendi commented 3 years ago

It did not happen to me two days ago, and I haven't changed anything locally AFAIK.