jquery - 由于生成器 ko 的 jQuery 错误,Gulp 失败了默认任务

标签 jquery knockout.js gulp yeoman

因此,我尝试在由 Yeoman generator-ko 生成的 Knockout 应用程序上运行 gulp。

我已将我的存储库(在我的 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 也会出现类似的问题,该文件仅包含:

}));

这几乎证实了我对其构建方式的想法。

有什么想法吗?

最佳答案

经过大量研究后,在 PR submitted 中找到了答案。作者:nenitiko

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

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

关于jquery - 由于生成器 ko 的 jQuery 错误,Gulp 失败了默认任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33198584/

相关文章:

javascript - Jquery 打开一个自定义模式链接而不是弹出窗口制造商的主题标签

javascript - Uncaught Error : Unable to parse bindings Knockout

javascript - 创建 ES6 类实例后可以立即将实例绑定(bind)到非静态方法吗?

javascript - 如何用 gulp 反转 Angular 脚本顺序注入(inject)?

javascript - 将标量变量转换为包含javascript中变量的数组

jquery - 根据滚动高度使 <div> 绝对定位

javascript - 全局变量表示未定义 - js

jquery - 嵌套 knockout foreach 模板

javascript - 使用 JSON 对象填充 KendoGrid

version - Laravel Elixir - 无法将 .version 与 css 和多个 js 文件一起使用