【问题标题】:The Ruby Racer, RuntimeError - SyntaxError: unexpected indentationRuby Racer,RuntimeError - SyntaxError:意外缩进
【发布时间】:2017-08-19 20:41:38
【问题描述】:

在旧应用程序上执行 ruby​​ 和 rails 升级后,我在尝试访问任何应用程序视图时收到以下错误:

SyntaxError: [stdin]:3:1: unexpected indentation

似乎某些与 The Ruby Racer gem 相关的文件可能会导致此问题。

Ruby 2.3.1p112、Rails 4.0.13、therubyracer 0.12.3

在服务器日志中:

ExecJS::RuntimeError - SyntaxError: [stdin]:3:1: unexpected indentation:
  execjs (2.7.0) lib/execjs/ruby_racer_runtime.rb:98:in `wrap_error'
  execjs (2.7.0) lib/execjs/ruby_racer_runtime.rb:47:in `rescue in block in call'
  execjs (2.7.0) lib/execjs/ruby_racer_runtime.rb:44:in `block in call'
  execjs (2.7.0) lib/execjs/ruby_racer_runtime.rb:75:in `block in lock'
  execjs (2.7.0) lib/execjs/ruby_racer_runtime.rb:73:in `lock'
  execjs (2.7.0) lib/execjs/ruby_racer_runtime.rb:43:in `call'
  coffee-script (2.4.1) lib/coffee_script.rb:78:in `compile'

更新

使用以前版本的 therubyracer,例如 gem 'therubyracer', '~> 0.10.2' 不能解决问题。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 therubyracer


    【解决方案1】:

    在编译您的一个咖啡脚本时出现编译错误。您应该检查 assets/javascript 文件夹中的 coffee 文件。

    为了帮助您更轻松地调试问题所在(哪一行),您可以尝试手动安装 coffee-script (http://coffeescript.org) 并使用命令行编译器。

    【讨论】:

    • 在升级过程中没有对咖啡脚本文件进行任何更改。我仔细检查了这几个短文件,但没有缩进问题。
    • 即使您没有对文件进行任何更改,仍然会出现咖啡脚本编译错误。因此,找出问题所在的一种方法是通过二分法进行。把你项目的所有coffee脚本文件都去掉,然后一一重新导入,直到找出问题所在。
    • 用编译器检查了其中一个文件。问题是这个文件:jQuery -> $('#subscription_product_tokens').tokenInput '/en/search_products.json' theme: 'facebook' prePopulate: $('#subscription_product_tokens').data('load') propertyToSearch: "full_description" 很奇怪。我将其重写为:jQuery -> $('#subscription_product_tokens').tokenInput '/en/search_products.json' theme: 'facebook' prePopulate: $('#subscription_product_tokens').data('load') propertyToSearch: "full_description"(“主题”行之前只有两个缩进空格。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-10
    相关资源
    最近更新 更多