Use dependencies in Hint when Installing - haskell

I'm writing a project using Haskell, stack and hint. I'm using hint to interpret a user-supplied module. The catch is that this module uses types and functions from a dependency. When I run my program using stack exec, everything works fine. However, when I install my program (using stack install --local-bin-path bin) and try to run the executable generated, the GHC interpreter fails with an error: Could not find module <module>. This is because (I think) it can't find the files needed for it to interpret source code referring to this dependency. Does anyone know how to fix this? I'm using Windows 10.
I've uploaded a minimal not-working example at https://github.com/bradrn/stack-overflow-hint-dependencies. It works fine if you do stack exec stack-overflow-hint-dependencies, but if you do stack install --local-bin-path bin it fails with Could not find module 'Data.Finite' when you try to interpret something.

Related

stack install error: Recommended extra-dep

I am currently trying to install stack to utilise the software Taiji. I have been able to run 'stack setup', but get an error when I run stack install:
C:\Users\My Name\Taiji-1.2.1>stack install
Error: While constructing the build plan, the following exceptions were encountered:
In the dependencies for shelly-1.8.1:
unix needed, but the stack configuration has no specified version (latest matching version is 2.7.2.2)
needed due to Taiji-1.2.1 -> shelly-1.8.1
Some different approaches to resolving this:
* Recommended action: try adding the following to your extra-deps in C:\Users\My Name\Taiji-1.2.1\stack.yaml:
- unix-2.7.2.2#sha256:9e93f93cc5a065248120136e83a0a6d1ce93d6eb5ef2a2543f9593e93e164d24,3496
Plan construction failed.
I am guessing I'll have to install another package of some sort and put it into the Taiji-1.2.1 folder, but am not exactly sure how(I am completely new to stack/programming). Is anyone able to help me with this issue? Thanks kindly.
When you see this error, you will need to open stack.yaml (the error message contains the full path), find the line saying # extra-deps: [], and replace it with the line shown in the error message:
extra-deps:
- unix-2.7.2.2#sha256:9e93f93cc5a065248120136e83a0a6d1ce93d6eb5ef2a2543f9593e93e164d24,3496
(If you already have something listed in extra-deps, then you can just add that line to the end of extra-deps rather than replacing the whole thing.)
Now, this is usually enough. But you’ve got a further problem: you are using Windows, but you’re trying to compile a program which depends on the unix package — a package which is not available on Windows. Due to this, you will not be able to compile your program on Windows.
(As for why all that extra-deps stuff is needed: basically, Stack maintains a list of package versions known to work with each other, but occasionally you will run into a package which isn’t in that list. In that case you will need to list that package version in extra-deps to tell Stack which version to use.)

npm pkg compiled executable error to run other executable file

After compiling a basic code to open a default browser, there's a warning.
After running , it product this error.
I am searching on pkg issues about this problem, an currently no solution binding with pkg compiler.
I am sharing my solution to this problem, so may be others save their time.
To solve the problem, after compiling a js code.
let's say you output the executable file to /folder_name/ .
copy node_modules/opn/xdg-open to /folder_name
and run it like on *nix: /folder_name $ ./execfile .

Cannot find module './build/Release/hdf5' in Electron

I installed the hdf5 node library, and it looked like it is in place. I am able to type require('hdf5') in command line, but when I run the electron wrapper, it gives me the error: Cannot find module './build/Release/hdf5'.
What could be the problem?
Even though the module is in my local directory, when I run the code with Electron, There is not such module under node_module.
Screenshot

PhantomJS from Node on Windows

I have written a Electron application using Node, Electron Boilerplate, and phantom. It works perfectly fine for me on my linux machine, I copied the source over to Windows 10, and ran with npm start, and all goes smoothly.
However, when I try to build the application with the boilerplate module using npm run release, things go a little less smoothly. I can install and open the application just fine, but when I click the button that activates the phantom module, the windows goes all white and nothing happens. I was able to logs some errors with the dev tools.
First, I have:
C:\...\dist\win-unpacked\resources\app.asar\node_modules\phantom\lib\phantom.js:361
Uncaught (in promise) Error: Error reading from stdin: Error: write EPIPE(…)
I did some research into similar issues, namely here, and it seems to me the issue is starting the child process, PhantomJS, with the npm module phantom. Originally, I was using a WPF application I wrote in C# to start the process, and that worked just fine. This leads me to believe that the phantom module is the culprit.
So I tried swapping out the npm phantom module for horseman, but got similar results:
Unhandled rejection HeadlessError: Phantom immediately exited with: 4294967295
at ChildProcess.immediateExit (C:\...\dist\win-unpacked\resources\app.asar\node_modules\node-horseman\node_modules\node-phantom-simple\node-phantom-simple.js:153:23)
at ChildProcess.g (events.js:286:16)
at emitTwo (events.js:106:13)
at ChildProcess.emit (events.js:191:7)
at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12)
Here is a shot in the dark. I am not positive this will solve your issue but here it goes:
GYP and miss-matched binaries
Phantom and many other node modules use binaries built for the specific OS that it will be running on. Sometimes in your npm log files you will see references to node-gyp. Node-gyp simply helps to build native add-on's in node modules. When the binaries are built they are usually built against, among others, three main parameters, the operating system, cpu architecture and version of node that is doing the installation.
I think you need to rebuild phantomjs to the version of node Electron is using. Most of the time the node version you have installed on your machine and the node version running in Electron are not the same. Electron does its best to keep up, but there is always a little lag because of the amount of work and testing required to keep up-to-date.
When you install phantom by running npm install phantom it will assume it needs to install or build the binaries for the node version your machine is using. Then when your Electron app tries to run phantom it tries to call the binary of the Electron's node version. When it isn't there the child process immediately exits with an error.
How to fix
Luckily, there are other people out there that have figured out how to fix this issue and have created a great tool to help generate the correct binaries.
Enter electron-rebuild:
https://github.com/electron/electron-rebuild
Electron-rebuild can be run in the command line, and it will rebuild all of your native modules to the version of Electron your project is using.
To install:
npm install electron-prebuilt
To use (in Windows):
.\node_modules\.bin\electron-rebuild.cmd
This should be enough to put the correct binaries in the right place.
Other thoughts
Sometimes you can use a package that uses a dependency called node-pre-gyp. E.g. sqlite3. There is a known issue I ended up running into when trying to rebuild my packages for Electron. Basically, in order to avoid this issue (if you run into it) just append --pre-gyp-fix to the above command.
Tangent for those who run into the pre-gyp-fix issue
One more thing on the pre-gyp-fix: If one or more of your dependencies depends on one of the modules that need the pre-gyp-fix then they will be looking for the binary in the wrong place even if they are running in Electron. All of the pre-gyp binaries are stored in a folder similar to this:
.\node_modules\sqlite3\lib\binding
In my current project I have three folders here, one for Electron-v1.4, and two for node-v46 and node-v50. (hack alert) In order to have sqlite3 work with my other dependencies I copy the binary found in the Electron-v1.4 folder and put it in both node-v* folders. That way when running in Electron, all dependencies are running the correct binaries even though they are looking for them in the wrong place. (end hack alert)
Conclusion
There is no way I can be sure this has anything to do with the issue you are seeing. But it is worth a shot to see if it fixes your problem. If not then at least I hope I can help someone else experiencing the same issues I ran into.

Cannot find module 'assetmanager'

I'm trying to run the MEAN stack on windows. I've installed all the pre-requisites (I think) but when I try to start the server via the gulp command I get the error:
Error: Cannot find module 'assetmanager'.
IMAGE:
I have tried running npm install assetmanager which run fine but I still get this error.
This is my first time trying to run node on a machine (I should have used a linux box) so go easy on me as I am learning :-).
Any and all help appreciated.
David
I had exactly the same problem on Linux Mint 17.2.
The failing way: This was my first project that I'd generated and I don't think I had all the dependencies installed before I ran the init command (g++ was missing).
I tried the npm install assetmanager command as you did and then install worked. Running gulp after this, it got further but this time I was missing mongoose. I installed that then it couldn't find .../config/env/all so I sylinked the default.js config. Then running gulp again, errorhandler was missing. I figured it shouldn't be this hard so...
The working way: I deleted that failure of a project and init'd a new one and it worked. Unfortunately I'm not sure if the init didn't work the first time but I missed the error/warning or something else caused it. All I can recommend is try creating another project and see if that works.

Resources