Skip to content
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

The example should probably switch to psc and make psa optional, or make external dependencies more clear #5

Closed
cyrbon opened this issue Feb 25, 2017 · 15 comments

Comments

@cyrbon
Copy link
Contributor

cyrbon commented Feb 25, 2017

Currently, if there is no purescript-psa installed, then the example fails with a very ambiguous error:

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: spawn psaa ENOENT
    at exports._errnoException (util.js:1026:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:359:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

This is going to be very discouraging for anybody who wants to quickly try purs-loader and purescript with webpack. On purs-loader page, it mentions quickly that it uses purescript-psa, but I think it's a good idea to make the example repository as fail-safe as possible and mention it loudly here as well.

My suggestion is to list every external dependency clearly upfront in the README.md. If I'm not missing anything, this consists of purescript-psa (psa) and purescript (psc), nodejs (node), webpack (webpack). I have specified their CLI names in brackets to that it's easier to verify whether each one exists by running --version on each of them. I can create a PL later.

@cyrbon cyrbon changed the title The example should probably switch to psc and make psa optional The example should probably switch to psc and make psa optional, or make external dependencies more clear Feb 25, 2017
@ethul
Copy link
Owner

ethul commented Feb 25, 2017

I think it is a great idea to be explicit about all of the dependencies. Putting this in the README would be a welcome addition. In terms of not having psa installed, shouldn't it be installed when the user runs npm install? I just want to make sure I understand how to reproduce the issue you had. Thanks!

@cyrbon
Copy link
Contributor Author

cyrbon commented Feb 25, 2017

No it's not installed. In my understanding, npm install does not install packages globally. You would need npm install -g purescript-psa for that. I'm on Nix, where it wouldn't allow npm command to install anything globally to begin with and since npm install runs without errors this means it alters only local packages, the ones that don't get added to $PATH.

@cyrbon
Copy link
Contributor Author

cyrbon commented Feb 25, 2017

I would try npm uninstall -g purescript-psa and then npm install again to test whether there was purescript-psa installed globally and to reproduce the issue.

@ethul
Copy link
Owner

ethul commented Feb 25, 2017

Right, the npm install would not install anything globally. But it should install psa locally in node_modules/.bin, and this is what the purs-loader expects. It should take the binaries in node_modules/.bin first when running webpack through npm. In the README it suggests npm start or npm run webpack:server. I believe this should pick up the local install of psa. Let me know if this works for you.

@cyrbon
Copy link
Contributor Author

cyrbon commented Feb 25, 2017

You're right npm run webpack:server works without global purescript-psa. npm start, on the other hand, outputs:

> npm run
Lifecycle scripts included in purescript-webpack-example:
  start
    node bundle.js

available via `npm run-script`:
  webpack
    DEBUG=purs-loader webpack --progress --bail
  webpack:watch
    webpack --progress --watch
  webpack:server
    webpack-dev-server --progress --inline --hot
  webpack:server:debug
    DEBUG=purs-loader webpack-dev-server --progress --inline --hot
  psc
    psc 'bower_components/purescript-*/src/**/*.purs' 'src/**/*.purs'
  psc-bundle
    psc-bundle output/**/*.js

@ethul
Copy link
Owner

ethul commented Feb 25, 2017

Glad it works! Note that for npm start, all steps are required as mentioned in the readme.

bower install

npm install

npm run webpack

npm start

@cyrbon
Copy link
Contributor Author

cyrbon commented Feb 25, 2017

Yeah, for npm start it's probably because npm run webpack failed and I tried doing it the other way. It failed like this:

>>> npm run webpack
> purescript-webpack-example@0.1.0 webpack /tmp/purescript-webpack-example
> DEBUG=purs-loader webpack --progress --bail
                                                                                                                                                                                  10% 0/1 build modules  purs-loader loader called Example +0ms
  purs-loader spawning compiler psa [ '--output=output', 'bower_components/purescript-*/src/**/*.purs', 'src/**/*.purs' ] +2ms
  purs-loader compiling PureScript... +4ms
  purs-loader finished compiling PureScript. +309ms
ModuleBuildError: Module build failed: Error: compilation failed
    at ChildProcess.<anonymous> (/tmp/purescript-webpack-example/node_modules/purs-loader/lib/Psc.js:48:16)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
    at DependenciesBlock.onModuleBuildFailed (/tmp/purescript-webpack-example/node_modules/webpack-core/lib/NormalModuleMixin.js:315:19)
    at nextLoader (/tmp/purescript-webpack-example/node_modules/webpack-core/lib/NormalModuleMixin.js:270:31)
    at /tmp/purescript-webpack-example/node_modules/webpack-core/lib/NormalModuleMixin.js:292:15
    at context.callback (/tmp/purescript-webpack-example/node_modules/webpack-core/lib/NormalModuleMixin.js:148:14)
    at Object.reject (/tmp/purescript-webpack-example/node_modules/purs-loader/lib/index.js:116:14)
    at /tmp/purescript-webpack-example/node_modules/purs-loader/lib/index.js:165:25
    at tryCatcher (/tmp/purescript-webpack-example/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/tmp/purescript-webpack-example/node_modules/bluebird/js/release/promise.js:510:31)
    at Promise._settlePromise (/tmp/purescript-webpack-example/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/tmp/purescript-webpack-example/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/tmp/purescript-webpack-example/node_modules/bluebird/js/release/promise.js:687:18)
    at Async._drainQueue (/tmp/purescript-webpack-example/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/tmp/purescript-webpack-example/node_modules/bluebird/js/release/async.js:143:10)
    at Immediate.Async.drainQueues (/tmp/purescript-webpack-example/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:637:20)
    at tryOnImmediate (timers.js:610:5)
    at processImmediate [as _immediateCallback] (timers.js:582:5)

npm ERR! Linux 4.4.35
npm ERR! argv "/nix/store/9ps69qzr5x9szkdk81gviyr9mck51nzn-nodejs-6.9.1/bin/node" "/home/jon/.nix-profile/bin/npm" "run" "webpack"
npm ERR! node v6.9.1
npm ERR! npm  v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! purescript-webpack-example@0.1.0 webpack: `DEBUG=purs-loader webpack --progress --bail`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the purescript-webpack-example@0.1.0 webpack script 'DEBUG=purs-loader webpack --progress --bail'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the purescript-webpack-example package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     DEBUG=purs-loader webpack --progress --bail
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs purescript-webpack-example
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls purescript-webpack-example
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /tmp/purescript-webpack-example/npm-debug.log

@cyrbon
Copy link
Contributor Author

cyrbon commented Feb 25, 2017

Anyway, there is something strange going on because it occasionally fails and occasionally not, even with npm run webpack:server. By occasionally, I mean if you use it for a while and run npm install, etc, not between individual runs. I found that the most reliable way is by running webpack and webpack --watch and having everything globally (purescript-psa and webpack), at least it's this way on Nix.

>>> npm run webpack:server

> purescript-webpack-example@0.1.0 webpack:server /tmp/purescript-webpack-example
> webpack-dev-server --progress --inline --hot
                                                                              70% 1/1 build modules http://localhost:4008/
webpack result is served from /
content is served from .                                                                           
ERROR in ./src/Example.purs
Module build failed: Error: compilation failed
    at ChildProcess.<anonymous> (/tmp/purescript-webpack-example/node_modules/purs-loader/lib/Psc.js:48:16)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)
    at Pipe._handle.close [as _onclose] (net.js:498:12)
 @ multi main

ERROR in events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: spawn /tmp/purescript-webpack-example/node_modules/purescript/vendor/psc ENOENT
    at exports._errnoException (util.js:1026:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
    at onErrorNT (internal/child_process.js:359:16)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)
    at Module.runMain (module.js:606:11)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:509:3

@ethul
Copy link
Owner

ethul commented Feb 25, 2017

Thanks for reporting this. I haven't tried it on Nix. I am not quite sure what is going on. Do you think it is related to the purs-loader or how npm is installing dependencies?

@cyrbon
Copy link
Contributor Author

cyrbon commented Feb 25, 2017

purs-loader works perfectly with webpack and webpack --watch.

I think I figured out what was causing this. This appears to be Nix related. Basically, npm puts the binary in /tmp/purescript-webpack-example/node_modules/purescript/vendor/psc, then something tries to spawn the process, after all, it obviously needs psc compiler to compile. However, that binary dynamically links /lib64/ld-linux-x86-64.so.2 that does not exist on this system:

> cd /tmp/purescript-webpack-example/node_modules/purescript/vendor/
> file ./psc
./psc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=d699fdefc2052263c93221500933c7431782f73a, stripped

Normally, Nix would patch it and provide another path to the library as seen here, when psc is installed through Nix:

> pwd
/nix/store/ilmpr6p1yga5sk3sqg5xhqwsbn301n7k-purescript-0.10.7/bin
> file ./psc
./psc: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /nix/store/amjgskg17wv125v9kahqdfxh8sx6mxgp-glibc-2.24/lib/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, stripped

In npm's case, if you even call ./psc from shell, it will output that file or directory does not exist. Not because the binary itself does not exist there, but because it links something that does not exist. It's very confusing and Linux should provide a clearer error in this case, IMO. When spawn called, it gets the same error that file does not exists and outputs the error as if psc does not exist there, which is not true.

So, when you run webpack that's installed globally it looks at $PATH for compiler and finds the one that is linked properly. When you run npm run it finds compiler that npm provided and fails.

@ethul
Copy link
Owner

ethul commented Feb 25, 2017

Great! Glad that you got this working. Do you think we should say anything about this in the troubleshooting section in the purs-loader README?

@cyrbon
Copy link
Contributor Author

cyrbon commented Feb 25, 2017

Yeah, probably. I think Nix usage among Purescript crowd will be higher than other JS transpilers, based on similarities in philosophy.

@ethul
Copy link
Owner

ethul commented Feb 25, 2017 via email

@cyrbon
Copy link
Contributor Author

cyrbon commented Feb 25, 2017

Of course. I'll create a pull request soon.

@ethul
Copy link
Owner

ethul commented Feb 25, 2017 via email

@cyrbon cyrbon closed this as completed Feb 25, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants