Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The following gulp task is not working on windows but working on ubuntu

The gulp task

/* Run the npm script npm run buildLsdk using gulp */
gulp.task('sdk', function() {
  if (process.cwd() != basePath) {
    process.chdir('..');
    // console.log(process.cwd());
  }
  spawn('./node_modules/.bin/lb-sdk', ['server/server.js', './client/src/app/shared/sdk', '-q'], {stdio: 'inherit'});
});

I am getting the following stack trace but i cannot debug

Error: spawn ./node_modules/.bin/lb-sdk ENOENT
    at exports._errnoException (util.js:1022: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:607:11)
    at run (bootstrap_node.js:420:7)
    at startup (bootstrap_node.js:139:9)
    at bootstrap_node.js:535:3

I have all the necessary files in node modules too any help is really appreciated.

More reference on the File use above - https://github.com/rahulrsingh09/loopback-Angular-Starter/blob/master/gulpfile.js

like image 825
Rahul Singh Avatar asked Dec 26 '17 14:12

Rahul Singh


Video Answer


1 Answers

I think it's because lb-sdk.cmd is the file you're supposed to run on windows. when I changed the command to the below the error goes away. Please note the windows style directory slashes are different from linux.

gulp.task('sdk', function() {
spawn(
  '.\\node_modules\\.bin\\lb-sdk.cmd',
  [
    '.\\server\\server.js',
    '.\\client\\src\\app\\shared\\sdk',
    '-q'
  ], {stdio: 'inherit'}
);
});

I found some more information,and I'm going to post a second answer I found (above one was accepted).

If you want to avoid changing directories in windows/linux you can use cross-spawn: https://www.npmjs.com/package/cross-spawn

win-spawn (from the chat dialog) is not maintained anymore per the github repo . If you're interested in using it make the following changes:

  1. npm install cross-spawn
  2. npm install spawn-sync
  3. npm install strongloop (needs to be reinstalled per this link)
  4. change 'google chrome' in browser-sync task to chrome.exe per this link:
  5. run gulp
like image 180
Jonathan Chaplin Avatar answered Nov 09 '22 02:11

Jonathan Chaplin