Gulp由于发生器ko的jQuery错误而失败的默认任务

问题描述:

所以我试图运行由Yeoman generator-ko生成的Knockout应用程序的吞噬。Gulp由于发生器ko的jQuery错误而失败的默认任务

我克隆了我的回购(在我的Macbook上构建的很好)到我的Windows 10盒子。如果我运行一饮而尽默认我得到以下错误(全光输出):

[14:33:41] Using gulpfile ~\Documents\GitHub\TMPrototype\Gulpfile.js 
[14:33:41] Starting 'html'... 
[14:33:41] Starting 'js:babel'... 
[14:33:41] Starting 'css'... 
[14:33:41] Finished 'html' after 46 ms 
[14:33:41] Finished 'css' after 198 ms 
[BABEL] Note: The code generator has deoptimised the styling of "src/bower_modules/knockout/dist/knockout.debug.js" as it exceeds the max of "100KB". 
[BABEL] Note: The code generator has deoptimised the styling of "src/bower_modules/jquery/dist/jquery.js" as it exceeds the max of "100KB". 
stream.js:94 
     throw er; // Unhandled stream error in pipe. 
      ^
SyntaxError: src/bower_modules/jquery/src/intro.js: Unexpected token (45:0) 
    43 | // you try to trace through "use strict" call chains. (#13335) 
    44 | //"use strict"; 
> 45 | 
    |^
    at Parser.pp.raise (C:\Users\Andrew\Documents\GitHub\TMPrototype\node_modules\babel-core\node_modules\babylon\lib\parser\location.js:24:13) 
    at Parser.pp.unexpected (C:\Users\Andrew\Documents\GitHub\TMPrototype\node_modules\babel-core\node_modules\babylon\lib\parser\util.js:82:8) 
    at Parser.pp.parseExprAtom (C:\Users\Andrew\Documents\GitHub\TMPrototype\node_modules\babel-core\node_modules\babylon\lib\parser\expression.js:425:12) 
    at Parser.parseExprAtom (C:\Users\Andrew\Documents\GitHub\TMPrototype\node_modules\babel-core\node_modules\babylon\lib\plugins\jsx\index.js:412:22) 
Process terminated with code 8. 
    at Parser.pp.parseExprSubscripts (C:\Users\Andrew\Documents\GitHub\TMPrototype\node_modules\babel-core\node_modules\babylon\lib\parser\expression.js:236:19) 
    at Parser.pp.parseMaybeUnary (C:\Users\Andrew\Documents\GitHub\TMPrototype\node_modules\babel-core\node_modules\babylon\lib\parser\expression.js:217:19) 
    at Parser.pp.parseExprOps (C:\Users\Andrew\Documents\GitHub\TMPrototype\node_modules\babel-core\node_modules\babylon\lib\parser\expression.js:163:19) 
    at Parser.pp.parseMaybeConditional (C:\Users\Andrew\Documents\GitHub\TMPrototype\node_modules\babel-core\node_modules\babylon\lib\parser\expression.js:145:19) 
    at Parser.pp.parseMaybeAssign (C:\Users\Andrew\Documents\GitHub\TMPrototype\node_modules\babel-core\node_modules\babylon\lib\parser\expression.js:112:19) 
    at Parser.pp.parseExpression (C:\Users\Andrew\Documents\GitHub\TMPrototype\node_modules\babel-core\node_modules\babylon\lib\parser\expression.js:79:19) 

当我浏览到bower_modules/jquery/src/intro.js参数功能未关闭。起初,我认为这只是通过在后面传递其余代码来编译的方式。

的jQuery/src目录/ intro.js(注意它是如何不关闭)

(function(global, factory) { 

    if (typeof module === "object" && typeof module.exports === "object") { 
     // For CommonJS and CommonJS-like environments where a proper `window` 
     // is present, execute the factory and get jQuery. 
     // For environments that do not have a `window` with a `document` 
     // (such as Node.js), expose a factory as module.exports. 
     // This accentuates the need for the creation of a real `window`. 
     // e.g. var jQuery = require("jquery")(window); 
     // See ticket #14549 for more info. 
     module.exports = global.document ? 
      factory(global, true) : 
      function(w) { 
       if (!w.document) { 
        throw new Error("jQuery requires a window with a document"); 
       } 
       return factory(w); 
      }; 
    } else { 
     factory(global); 
    } 

// Pass this if window is not defined yet 
}(typeof window !== "undefined" ? window : this, function(window, noGlobal) { 

// Support: Firefox 18+ 
// Can't be in strict mode, several libs including ASP.NET trace 
// the stack via arguments.caller.callee and Firefox dies if 
// you try to trace through "use strict" call chains. (#13335) 
//"use strict"; 

如果我解决,通过关闭它,outro.js也有类似的问题,该文件只包含:

})); 

这几乎证实了我对它是如何构建的想法。

任何想法?

+0

今天有同样的问题。你有没有运气? –

+0

@AndreGallo不好意思,虽然令人难以置信的令人沮丧。我正在考虑在这方面给予奖励。 –

+0

@Jezzabeans它似乎是一个环境问题。该发生器在我的Macbook Pro(OSX El capitan)上运行正常,但在我的Windows 10 VM上失败。如果我发现潜在的问题是什么,我会发布一个答案... –

经过大量的挖掘后,找到了答案PR submittednenitiko

这是关于在OSX/Win环境中正向/反向斜杠目录分隔符的区别。

所以要解决它,请在您的gulp文件中添加对slash = require('slash');的引用。然后pathname = slash(pathname);babelTranspile函数。

+0

谢谢安德烈,一旦我回家,我会测试这个。 –

+0

经过测试,它工作得很好,谢谢你找到这个安德烈。享受赏金。编辑:只能在10小时内奖励它。 –

+0

你简直就是人间的神哈哈!非常感谢您对此进行调试。 – pimbrouwers