Rahul Singh
Rahul Singh

Reputation: 19632

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

Upvotes: 13

Views: 1051

Answers (3)

Jonathan Chaplin
Jonathan Chaplin

Reputation: 2482

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

Upvotes: 4

Nah
Nah

Reputation: 1768

Please refer to this similar answer, this will solve your issue:

Convert the following npm script to gulp task

How to automate the build from the following configuration using gulp

And you can check the documentation of lb-sdk by typing ./node_modules/.bin/lb-sdk in your terminal.

Upvotes: 0

Krasimir
Krasimir

Reputation: 13539

Can you try using basePath when passing server/server.js and ./client/src/app/shared/sdk. Like for example:

spawn(
  './node_modules/.bin/lb-sdk',
  [
    basePath + '/server/server.js',
    basePath + '/client/src/app/shared/sdk',
    '-q'
  ], {stdio: 'inherit'}
);

Upvotes: -1

Related Questions