purescript-deprecated / gulp-purescript

Gulp plugin providing PureScript compiler tasks
34 stars 8 forks source link

Error: spawn psc ENOENT #30

Closed JohnGurin closed 9 years ago

JohnGurin commented 9 years ago
$ gulp
[12:05:33] Using gulpfile ~\Documents\Purescript\gulpfile.js
[12:05:33] Starting 'purescript'...
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: spawn psc ENOENT
    at exports._errnoException (util.js:746:11)
    at Process.ChildProcess._handle.onexit (child_process.js:1046:32)
    at child_process.js:1137:20
    at process._tickCallback (node.js:355:11)
//gulpfile.js
var gulp = require('gulp');
var purescript = require('gulp-purescript');

gulp.task('purescript', function(){
  return gulp.src('src/**/*.purs').
         pipe(purescript.psc({main:"Chapter2"})). //<-- if this line is commented the script works
         pipe(gulp.dest('build'));
});
gulp.task('default', ['purescript']);
-- Chapter2.purs
module Chapter2 where
import Debug.Trace
main = trace "Hello"
$ node -v
v0.12.1

$ npm -v
2.5.1

$ gulp -v
[12:05:49] CLI version 3.8.11
[12:05:49] Local version 3.8.11
#local node_modules
gulp\
gulp-dest\
gulp-purescript\
gulp-util\
logalot\
minimist\
multipipe\
resolve-bin\
through2\
which\
#this works
john@HOME-PC ~/Documents/Purescript
$ psc src/Chapter2.purs --output dist/Main.js --main=Chapter2 --module=Chapter2

Windows 8.1 x64

ethul commented 9 years ago

Thanks for the report. I haven't tried the library with node 0.12.x. I will take a look.

garyb commented 9 years ago

I'm using node 0.12.2 so I'm not necessarily sure it's related to that.

@JohnGurin what do you get for where psc?

JohnGurin commented 9 years ago

@garyb

john@HOME-PC ~/Documents/Purescript
$ where psc
c:\Users\john\AppData\Roaming\npm\psc
c:\Users\john\AppData\Roaming\npm\psc.cmd
ethul commented 9 years ago

Could the issue be: https://github.com/npm/npm/wiki/Troubleshooting#error-enoent-stat-cusersuserappdataroamingnpm-on-windows-7

JohnGurin commented 9 years ago

So, I think I found the problem. http://stackoverflow.com/a/17537559 Made the gulp-purescript work by adding

// node_modules\gulp-purescript\index.js line:2196
function spawnFn(command, args, errback, callback) {
      command = command + ".cmd";  //<-- added this line
      return function(){
        var child_process = __webpack_require__(35);
        var process = child_process.spawn(command, args);
...

Now the gulp compiles *.purs to psc.js ignoring options

ethul commented 9 years ago

@JohnGurin thanks for digging into this.

I wonder if we are running into joyent/node#2318

From that thread, it looks like one solution is to drop-in the following replacement for spawn. https://github.com/IndigoUnited/node-cross-spawn

Would you possibly be able to try this module locally to see if it solves the problem (without adding the .cmd extension)? Sorry that I can't give this a go myself. I don't have access to windows at all.

Not sure if this is the best way to go, but might be worth a try.

JohnGurin commented 9 years ago
// node_modules\gulp-purescript\index.js line:2196
function spawnFn(command, args, errback, callback) {
      command = command + ".cmd";  //<-- added this line
      return function(){
        //var child_process = __webpack_require__(35);
        //var process = child_process.spawn(command, args);
           console.log(command);
        var process = require('cross-spawn')(command, args); //<-- added this line
...

results in the same as in previous attempt: gulp works but purescript.psc(options) options is not respected.

ethul commented 9 years ago

Thanks for giving this a try @JohnGurin

Did you happen to try it without adding the .cmd to command? I.e., removing:

command = command + ".cmd";  //<-- added this line

So it would be

// node_modules\gulp-purescript\index.js line:2196
function spawnFn(command, args, errback, callback) {
      return function(){
        //var child_process = __webpack_require__(35);
        //var process = child_process.spawn(command, args);
        var process = require('cross-spawn')(command, args); //<-- added this line
...

If this does not work as well, what are the options passed to psc? Can you please provide the values of command and args?

Thanks for all of this!

JohnGurin commented 9 years ago
gulp.task('purescript', function(){
  return gulp.src('src/**/*.purs').
         pipe(purescript.psc({noPrelude:true,main:'Chapter2',module:'Chapter2'})).
         pipe(gulp.dest('build'));
});

Sorry, I tested without command = command + ".cmd";, copy pasted it from previous message and missed the line. console.log(command) prints psc

ethul commented 9 years ago

Ah, no worries. Thanks for the info. Just for good measure, would you mind console.log-ing the command and args variables and providing the output? I.e., the precise values passed to cross-spawn.

Thanks!

JohnGurin commented 9 years ago
function spawnFn(command, args, errback, callback) {
     return function(){
        //var child_process = __webpack_require__(35);
        //var process = child_process.spawn(command, args);
        console.log(command);
        console.log(args);
        var process = require('cross-spawn')(command, args);
...
john@HOME-PC ~/Documents/Purescript
$ gulp purescript
[19:03:52] Using gulpfile ~\Documents\Purescript\gulpfile.js
[19:03:52] Starting 'purescript'...
psc
[ 'C:\\Users\\john\\Documents\\Purescript\\src\\Chapter2.purs' ]
[19:03:52] Finished 'purescript' after 407 ms
ethul commented 9 years ago

Interesting. The value of args looks to be missing your options passed to psc in the gulpfile.

Perhaps cross-spawn is working properly, but somewhere outside of spawnFn the options are getting lost. I will look into this further, but if you have a chance to trace back the args value a bit to see where they might be getting lost, it would be a great help!

JohnGurin commented 9 years ago
// node_modules\gulp-purescript\index.js line:191
var psc = function (opts) {
        console.log(opts); //<--
            var run = function (i) {
            var _1330 = GulpPurescript_Options.pscOptionsNoOutput(opts);
        console.log(_1330); //<--
            return Prelude["<$>"]/*...*/(_1330.value0)))(/*...*/)(_1330.value1)));
        };
        return Prelude["<*>"]/*...*/(run));
    };
john@HOME-PC ~/Documents/Purescript
$ gulp purescript
[19:33:57] Using gulpfile ~\Documents\Purescript\gulpfile.js
[19:33:57] Starting 'purescript'...
{ noPrelude: true, main: 'Chapter2', module: 'Chapter2' }
{ value0: {}, value1: [] }
[19:33:57] Finished 'purescript' after 424 ms

btw, what is the right way to traceback nodejs?

ethul commented 9 years ago

Thanks!

What version of gulp-purescript are you on? Can you please try this with 0.4.2?

There was a previous fix (#24) for parsing the psc main option. Maybe an update will solve the options issue. If so, I can migrate to using cross-spawn.

And the way you traced is how I would have done it. Not sure if there is a better way.

JohnGurin commented 9 years ago
// node_modules\gulp-purescript\package.json 
...
"version": "0.4.2", 
...
ethul commented 9 years ago

Thanks. Okay. There must still be an issue here. I will take a look. Thanks again for all of your help.

ethul commented 9 years ago

I noticed that the module option should be an array of strings. Instead of

purescript.psc({noPrelude:true,main:'Chapter2',module:'Chapter2'})

it should be

purescript.psc({noPrelude:true,main:'Chapter2',module:['Chapter2']})

I think this may do the trick to solve the options problem. However, I am thinking the plugin should provide an error message when an option has the wrong type. I've opened a separate issue #31 for this.

If this works, I will use cross-spawn to provide cross-platform command invocation.

JohnGurin commented 9 years ago
john@HOME-PC ~/Documents/Purescript
$ gulp purescript
[23:02:39] Using gulpfile ~\Documents\Purescript\gulpfile.js
[23:02:39] Starting 'purescript'...
{ noPrelude: true, main: 'Chapter2', module: [ 'Chapter2' ] }
{ value0: {},
  value1: [ '--no-prelude', '--main=Chapter2', '--module=Chapter2' ] }
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: Error in module Chapter2:
Error at C:\Users\john\Documents\Purescript\src\Chapter2.purs line 3, column 1 - line 5, column 1:
  Unknown module Debug.Trace
See https://github.com/purescript/purescript/wiki/Error-Code-UnknownModule for more information, or to contribute conten
t related to this error.
...

Oops. noPrelude:true is the cause. Everything works purescript.psc({main:"Chapter2",module:["Chapter2"]})

ethul commented 9 years ago

@JohnGurin Just to confirm, having noPrelude:true was causing the ENOENT error?

Glad it works now by the way!

JohnGurin commented 9 years ago

No, only

Error: Error in module Chapter2:
Error at C:\Users\john\Documents\Purescript\src\Chapter2.purs line 3, column 1 - line 5, column 1:
  Unknown module Debug.Trace

Switching to non-cross-spawn brings ENOENT back. So ENOENT issue is resolved.

ethul commented 9 years ago

To clarify, when cross-spawn is not being used (i.e., vanilla gulp-purescript @ 0.4.2), do you still get the ENOENT error? Given that you are using the options:

purescript.psc({main:"Chapter2",module:["Chapter2"]})

Thanks!

JohnGurin commented 9 years ago

Yes

ethul commented 9 years ago

Thanks. I will reopen the issue and add cross-spawn.

ethul commented 9 years ago

Released in version 0.4.3. Please let me know if it works for you.

Thanks!

JohnGurin commented 9 years ago

:+1:

doivosevic commented 8 years ago

I have just tried installing purescript-angular from scratch and after following the steps I got the same error as mentioned at the beginning of this article. I have Node 4.2.1 and npm 2.14.7 . I have tried changing

"gulp-purescript": "0.1.2",

to

"gulp-purescript": "*",

but then i got

[14:55:01] Warning: gulp version mismatch:
[14:55:01] Global gulp is 3.9.0
[14:55:01] Local gulp is 3.8.10
[14:55:02] Using gulpfile ~\Desktop\purescript-angular\gulpfile.js
[14:55:02] Starting 'clean'...
[14:55:02] Finished 'clean' after 25 ms
[14:55:02] Starting 'todomvc'...
[14:55:02] 'todomvc' errored after 11 ms
[14:55:02] Error in plugin 'gulp-purescript'
Message:
    Type mismatch: expected array, found Undefined
ethul commented 8 years ago

@DominikDitoIvosevic would you be able to verify the version of gulp-purescript you have installed? Also, have you tried to match your local gulp with your global gulp version?