ruby on rails 中的 Coffeescript 编译错误 [英] Coffeescript compilation error in ruby on rails

查看:23
本文介绍了ruby on rails 中的 Coffeescript 编译错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 coffeescript+ruby-on-rails.将coffeescript编译成纯JS会导致coffee代码语法有问题.在浏览器上运行应用程序时,出现此错误:

以下是服务器日志中的条目,这并不能说明实际导致语法错误的文件:

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 网站" %></title>6:<meta name="description" content="<%= content_for?(:description) ? yield(:description) : "Inmonarch Website" %>">7: <%= stylesheet_link_tag 'application', media: 'all' %>8: <%= javascript_include_tag '应用程序'%>9:<%= csrf_meta_tags %>10:</头>app/views/layouts/dashboard.html.erb:7:in`_app_views_layouts_dashboard_html_erb__3120053487817944018_56303120'渲染/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/_source.erb (7.4ms)渲染/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)渲染/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)在救援/布局中渲染/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/actionpack-4.2.6/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb (25.5ms)渲染/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/_markup.html.erb (0.3ms)渲染/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/_inner_console_markup.html.erb 在 layouts/inlined_string (0.3ms)渲染/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/_prompt_box_markup.html.erb 在 layouts/inlined_string (0.3ms)渲染/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/style.css.erb 在 layouts/inlined_string (0.3ms)渲染/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/console.js.erb 在 layouts/javascript (296.8ms)渲染/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/main.js.erb 在 layouts/javascript (0.2ms)渲染/home/vipin8169/.rvm/gems/ruby-2.2.3@rails426/gems/web-console-2.3.0/lib/web_console/templates/error_page.js.erb 在 layouts/javascript (0.3ms)渲染/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 文件夹(只有在修复所有错误时才会创建).这应该会为您找到语法错​​误并告诉您它的确切位置.

I am using coffeescript+ruby-on-rails. The compilation of coffeescript into pure JS leads to an error if there is a syntax problem in the coffee code. On the browser when I run the app, I get this error: ExecJS::RuntimeError

Is there any way to find out what caused the compilation error, when it was trying to compile coffee code to JS? Attached is a screenshot of the error

Following is the entry in the server log, which no way indicates the file which actually caused the syntax error:

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:- I know what the syntax error is, I made the syntax error deliberately to find out if I am able to trace the error with the help of logs, which I couldn't.

解决方案

One workaround is to compile your .coffee files outside rails to get a decent error message:

If you don't yet have it:

npm i coffee-script -g

Then in a parent directory of your .coffee files:

coffee --output deleteme --compile .

When you're done, delete the deleteme folder it created (which is only created if you fix all the errors). This should find the syntax error for you and tell you exactly where it is.

这篇关于ruby on rails 中的 Coffeescript 编译错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆