Gulp 由于 generator-ko 的 jQuery 错误导致默认任务失败

Gulp failing default task due to jQuery error for generator-ko

所以我正在尝试 运行 gulp 在由 Yeoman generator-ko 生成的 Knockout 应用程序上

我已将我的存储库(在我的 Macbook 上构建良好)克隆到我的 Windows 10 盒子。如果我 运行 gulp 默认我得到以下错误(完整输出):

[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 有一个类似的问题,该文件仅包含:

}));

这几乎可以证实我对它的构建方式的看法。

有什么想法吗?

在对此进行大量挖掘之后,在 nenitikoPR submitted 中找到了答案。

这与 OSX/Win 环境中 forward/backward-slash 目录分隔符的差异有关。

因此,要修复它,请在 gulp 文件中添加对 slash = require('slash'); 的引用。然后 pathname = slash(pathname);babelTranspile 函数。