javascript - 以下 gulp 任务不适用于 Windows,但适用于 ubuntu

标签 javascript gulp

gulp 任务

/* 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'});
});

我得到以下堆栈跟踪但我无法调试

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

我在节点模块中也有所有必要的文件,非常感谢任何帮助。

有关上述文件使用的更多引用 - https://github.com/rahulrsingh09/loopback-Angular-Starter/blob/master/gulpfile.js

最佳答案

我认为这是因为 lb-sdk.cmd 是您应该在 Windows 上运行的文件。当我将命令更改为以下时,错误消失了。请注意 windows 风格的目录斜杠与 linux 不同。

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

我找到了更多信息,我将发布我找到的第二个答案(上面的答案已被接受)。

如果你想避免在 windows/linux 中改变目录,你可以使用 cross-spawn: https://www.npmjs.com/package/cross-spawn

win-spawn(来自聊天对话框)不再维护 per the github repo .如果您有兴趣使用它,请进行以下更改:

  1. npm 安装 cross-spawn
  2. npm 安装 spawn-sync
  3. npm 安装 strongloop (needs to be reinstalled per this link)
  4. 将浏览器同步任务中的“google chrome”更改为 chrome.exe per this link :
  5. 运行 gulp

关于javascript - 以下 gulp 任务不适用于 Windows,但适用于 ubuntu,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47979754/

相关文章:

javascript - 防止用户多次单击 'like' 的最佳方法

javascript - 从链接函数 angularJs 在 UI 中显示数据

javascript - Json GET 未在弹出窗口中显示详细信息

javascript - Jquery仅切换 child

gulp - 运行 Gulp,我收到此错误 : File to import not found or unreadable: util/util

javascript - 如何缩小 gulp-webpack 文件?

javascript - AngularJS 服务对象未在 View / Controller 之间更新

node.js - 使用基本目录时 Gulp 不复制文件

node.js - 在gulp中执行任意 Node 脚本

javascript - Gulp 和 Babel : Error: Cannot find module