rails ruby 中的 Coffeescript 编译错误
Coffeescript compilation error in ruby on rails
我正在使用 coffeescript+ruby-on-rails。 coffeescript编译成纯JS,如果coffee代码有语法问题,就会报错。在浏览器上,当我 运行 应用程序时,出现此错误:ExecJS::RuntimeError
有什么方法可以找出编译错误的原因,当它试图将咖啡代码编译为 JS 时?
附上错误截图
以下是服务器日志中的条目,它无法指示实际导致语法错误的文件:
ActionView::Template::Error (SyntaxError: [stdin]:25:10: unexpected :):
4: <meta name="viewport" content="width=device-width, initial-scale=1.0">
5: <title><%= content_for?(:title) ? yield(:title) : "Inmonarch Website" %></title>
6: <meta name="description" content="<%= content_for?(:description) ? yield(:description) : "Inmonarch Website" %>">
7: <%= stylesheet_link_tag 'application', media: 'all' %>
8: <%= javascript_include_tag 'application' %>
9: <%= csrf_meta_tags %>
10: </head>
app/views/layouts/dashboard.html.erb:7:in `_app_views_layouts_dashboard_html_erb__3120053487817944018_56303120'
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (7.4ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.0ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.6ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (25.5ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.3ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.3ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (296.8ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.2ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.3ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (313.8ms)
PS:- 我知道语法错误是什么,我故意犯语法错误是为了找出我是否能够借助日志来跟踪错误,但我做不到。
一个解决方法是在 rails 之外编译您的 .coffee
文件以获得正确的错误消息:
如果您还没有:
npm i coffee-script -g
然后在您的 .coffee
文件的父目录中:
coffee --output deleteme --compile .
完成后,删除它创建的 deleteme
文件夹(只有在修复所有错误后才会创建)。这应该会为您找到语法错误并告诉您确切位置。
如果您知道它的 coffeescript 导致错误,您可以使用像 http://www.coffeelint.org/ 这样的在线 linter
我正在使用 coffeescript+ruby-on-rails。 coffeescript编译成纯JS,如果coffee代码有语法问题,就会报错。在浏览器上,当我 运行 应用程序时,出现此错误:ExecJS::RuntimeError
有什么方法可以找出编译错误的原因,当它试图将咖啡代码编译为 JS 时?
附上错误截图
以下是服务器日志中的条目,它无法指示实际导致语法错误的文件:
ActionView::Template::Error (SyntaxError: [stdin]:25:10: unexpected :):
4: <meta name="viewport" content="width=device-width, initial-scale=1.0">
5: <title><%= content_for?(:title) ? yield(:title) : "Inmonarch Website" %></title>
6: <meta name="description" content="<%= content_for?(:description) ? yield(:description) : "Inmonarch Website" %>">
7: <%= stylesheet_link_tag 'application', media: 'all' %>
8: <%= javascript_include_tag 'application' %>
9: <%= csrf_meta_tags %>
10: </head>
app/views/layouts/dashboard.html.erb:7:in `_app_views_layouts_dashboard_html_erb__3120053487817944018_56303120'
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (7.4ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.0ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.6ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (25.5ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.3ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.3ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.3ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb within layouts/javascript (296.8ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb within layouts/javascript (0.2ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.3ms)
Rendered /home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/index.html.erb (313.8ms)
PS:- 我知道语法错误是什么,我故意犯语法错误是为了找出我是否能够借助日志来跟踪错误,但我做不到。
一个解决方法是在 rails 之外编译您的 .coffee
文件以获得正确的错误消息:
如果您还没有:
npm i coffee-script -g
然后在您的 .coffee
文件的父目录中:
coffee --output deleteme --compile .
完成后,删除它创建的 deleteme
文件夹(只有在修复所有错误后才会创建)。这应该会为您找到语法错误并告诉您确切位置。
如果您知道它的 coffeescript 导致错误,您可以使用像 http://www.coffeelint.org/ 这样的在线 linter