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

时间:2015-10-18 13:39:49

标签: jquery knockout.js gulp yeoman

所以我试图在我的Knockout应用程序上运行gulp,该应用程序由Yeoman generator-ko生成。

我克隆了我的回购(在我的Macbook上构建得很好)到我的Windows 10盒子。如果我运行gulp default我得到以下错误(完整输出):

[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会出现类似文件的问题:

}));

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

有什么想法吗?

1 个答案:

答案 0 :(得分:6)

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

这与OSX / Win环境中前向/后向斜杠目录分隔符的差异有关。

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