How do I debug “Error: spawn ENOENT” on node.js?

后端 未结 25 2666
轻奢々
轻奢々 2020-11-22 03:00

When I get the following error:

events.js:72
        throw er; // Unhandled \'error\' event
              ^
Error: spawn ENOENT
    at errnoException (chil         


        
25条回答
  •  北海茫月
    2020-11-22 03:33

    I ran into this problem on Windows, where calling exec and spawn with the exact same command (omitting arguments) worked fine for exec (so I knew my command was on $PATH), but spawn would give ENOENT. Turned out that I just needed to append .exe to the command I was using:

    import { exec, spawn } from 'child_process';
    
    // This works fine
    exec('p4 changes -s submitted');
    
    // This gives the ENOENT error
    spawn('p4');
    
    // But this resolves it
    spawn('p4.exe');
    // Even works with the arguments now
    spawn('p4.exe', ['changes', '-s', 'submitted']);
    

提交回复
热议问题