【问题标题】:Guard-Uglify throws "only generation of JSON objects or arrays allowed"Guard-Uglify 抛出“只允许生成 JSON 对象或数组”
【发布时间】:2013-08-24 00:01:51
【问题描述】:

我正在尝试使用guard uglify javascript,但出现以下错误:

错误 - Guard::Uglify 未能实现它,异常是: [#] JSON::GeneratorError: 只允许生成 JSON 对象或数组 [#] C:/Ruby193/lib/ruby/1.9.1/json/common.rb:216:in generate' [#] C:/Ruby193/lib/ruby/1.9.1/json/common.rb:216:ingenerate' [#] C:/Ruby193/lib/ruby/1.9.1/json/common.rb:352:in dump' [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-2.0.0/lib/execjs/external_runtime.rb:53:inblock (2 级) in compile' [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-2.0.0/lib/execjs/external_runtime.rb:51:in sub!' [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-2.0.0/lib/execjs/external_runtime.rb:51:inblock in compile' [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-2.0.0/lib/execjs/external_runtime.rb:47:in tap' [#] C:/Ruby193/lib/ruby/gems/1.9.1/gems/execjs-2.0.0/lib/execjs/external_runtime.rb:47:incompile'

我正在使用 json 2.0.0(也尝试过 1.8.0)和 mutli-json 1.7.8(也尝试过 1.7.9)

编辑

Guardfile 中的代码

guard 'uglify', :destination_file => "js/scripts.min.js" do
  watch 'js/scripts.min.js'
end

【问题讨论】:

    标签: ruby guard uglifyjs


    【解决方案1】:

    这应该与您的 javascript 代码格式不正确有关。

    如果您不知道错误可能出在哪里,您可以尝试单独丑化部分代码,直到找到引发错误的代码。

    【讨论】:

    • 当我编译空文件或像“var a = 1;”这样简单的东西时也会发生同样的事情
    • 我的其他回答对你有帮助吗?
    • 其实我刚切换到 Grunt。事实证明它更容易、更直观,但无论如何,感谢您的帮助。
    【解决方案2】:

    能否请您显示调用 Guard 的 uglify 的代码。

    它可能与您传递给 Guard 的对象相关联。 => 你需要读取文件并解析它。

        JSON.parse(string or file read)
    

    【讨论】:

      猜你喜欢
      • 2013-08-26
      • 1970-01-01
      • 2013-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      • 1970-01-01
      相关资源
      最近更新 更多