React-rails: Component with { prerender: true } in options hash gives a V8:Error - Unexpected token < -
i'm using react-rails
gem in project.
whenever pass in prerender: true
alternative options hash of react_component
helper method, error: v8::error - unexpected token <
. component works fine when remove prerender: true
options hash.
gemfile:
gem 'rails', '4.1.1' gem 'execjs' gem 'therubyracer', platforms: :ruby gem 'react-rails', github: 'reactjs/react-rails'
the view:
= react_component("assignmentwindowprogressbar", { assignment: @assignment_json }, { prerender: true })
coffee file:
###* @jsx react.dom ### @assignmentwindowprogressbar = react.createclass render: -> `<div>hi world.</div>` # located in file: # ./apps/assets/javascripts/components/assignments/assignmentwindows.js.jsx.coffee
stack trace:
v8::error - unexpected token < @ <eval>:19037:15: therubyracer (0.12.1) lib/v8/error.rb:86:in `block in try' therubyracer (0.12.1) lib/v8/error.rb:83:in `try' therubyracer (0.12.1) lib/v8/context.rb:95:in `block in eval' therubyracer (0.12.1) lib/v8/context.rb:248:in `block (2 levels) in lock_scope_and_enter' therubyracer (0.12.1) lib/v8/context.rb:245:in `block in lock_scope_and_enter' therubyracer (0.12.1) lib/v8/context.rb:244:in `lock_scope_and_enter' therubyracer (0.12.1) lib/v8/context.rb:204:in `enter' therubyracer (0.12.1) lib/v8/context.rb:94:in `eval' execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:11:in `block in initialize' execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:78:in `block in lock' execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:76:in `lock' execjs (2.2.0) lib/execjs/ruby_racer_runtime.rb:9:in `initialize' execjs (2.2.0) lib/execjs/runtime.rb:44:in `compile' execjs (2.2.0) lib/execjs/module.rb:27:in `compile' ... end of execjs errors ...
thanks , help guys!
copied reply https://github.com/reactjs/react-rails#jsx
to transform jsx js, create .js.jsx files. these files transformed on request, or precompiled part of assets:precompile task.
coffeescript files can used, creating .js.jsx.coffee files. need embed jsx within backticks coffeescript ignores syntax doesn't understand. here's example:
component = react.createclass render: -> `<examplecomponent videos={this.props.videos} />`
notice file extension.
ruby-on-rails ruby-on-rails-4 v8 reactjs execjs
Great Article
ReplyDeleteAngular 5 Development Company
Angular 5 Training in CHennai