Cannot set property 'root' of null
My apologies if this is the wrong place to put this, but I can't find the git repo for coffee-script-source.
We have a Rails 4.1.9 app and a strange error has started to occur after upgrading our dependencies.
With the latest version of gem 'coffee-script-source', '=1.9.0' we receive the following error when trying to precompile our assets.
We have confirmed that rolling back to v1.7.1 fixes the issue.
I believe that this was caused by #3498.
We have looked at the offending file tags.js.coffee and could find no obvious errors. When we remove that file, the same error occurs on another file.
> rm -rf public/assets/ && rm -rf tmp/cache/
> RAILS_GROUP=assets RAILS_ENV=production bundle exec rake assets:precompile
...
...
...
rake aborted!
ExecJS::ProgramError: TypeError: Cannot set property 'root' of null
(in /Users/a/Development/pc/app/assets/javascripts/widgets/tags.js.coffee)
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:58:in `rescue in block in call'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:52:in `block in call'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:87:in `block in lock'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:85:in `call'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:85:in `Locker'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:85:in `lock'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:51:in `call'
/Users/a/.rvm/gems/ruby-2.1.4/gems/coffee-script-2.3.0/lib/coffee_script.rb:76:in `compile'
/Users/a/.rvm/gems/ruby-2.1.4/gems/tilt-1.4.1/lib/tilt/coffee.rb:46:in `evaluate'
/Users/a/.rvm/gems/ruby-2.1.4/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/context.rb:197:in `block in evaluate'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `each'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `evaluate'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `new'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:373:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:105:in `each'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:97:in `build_required_assets'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:16:in `initialize'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `new'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:373:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:105:in `each'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:97:in `build_required_assets'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:16:in `initialize'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `new'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:373:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/bundled_asset.rb:16:in `initialize'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:377:in `new'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:377:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:211:in `block in find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:257:in `benchmark'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:210:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:119:in `block in compile'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:118:in `each'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:118:in `compile'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-rails-2.2.4/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/rake/sprocketstask.rb:146:in `with_logger'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-rails-2.2.4/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
/Users/a/.rvm/gems/ruby-2.1.4/bin/ruby_noexec_wrapper:14:in `eval'
/Users/a/.rvm/gems/ruby-2.1.4/bin/ruby_noexec_wrapper:14:in `<main>'
V8::Error: Cannot set property 'root' of null
at e (<eval>:10:2965)
at e.Code.t.makeScope (<eval>:11:3727)
at e.Code.t.compileNode (<eval>:11:4190)
at e.Base.e.compileToFragments (<eval>:10:6441)
at e.Assign.n.compileNode (<eval>:10:32155)
at e.Base.e.compileToFragments (<eval>:10:6441)
at e.Obj.t.compileNode (<eval>:10:26117)
at e.Base.e.compileToFragments (<eval>:10:6441)
at e.Value.t.compileNode (<eval>:10:17090)
at e.Base.e.compileToFragments (<eval>:10:6441)
at e.Assign.n.compileNode (<eval>:10:32155)
at e.Base.e.compileToFragments (<eval>:10:6441)
at e.Block.t.compileNode (<eval>:10:10361)
at e.Block.t.compileWithDeclarations (<eval>:10:11811)
at e.Block.t.compileRoot (<eval>:10:11313)
at e.Block.t.compileToFragments (<eval>:10:10098)
at <eval>:11:30692
at <eval>:11:30332
at <eval>:3:33
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:53:in `block in call'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:87:in `block in lock'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:85:in `call'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:85:in `Locker'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:85:in `lock'
/Users/a/.rvm/gems/ruby-2.1.4/gems/execjs-2.3.0/lib/execjs/ruby_racer_runtime.rb:51:in `call'
/Users/a/.rvm/gems/ruby-2.1.4/gems/coffee-script-2.3.0/lib/coffee_script.rb:76:in `compile'
/Users/a/.rvm/gems/ruby-2.1.4/gems/tilt-1.4.1/lib/tilt/coffee.rb:46:in `evaluate'
/Users/a/.rvm/gems/ruby-2.1.4/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/context.rb:197:in `block in evaluate'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `each'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/context.rb:194:in `evaluate'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:12:in `initialize'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `new'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:373:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:105:in `each'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:97:in `build_required_assets'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:16:in `initialize'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `new'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:373:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:111:in `block in resolve_dependencies'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:105:in `each'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:105:in `resolve_dependencies'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:97:in `build_required_assets'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/processed_asset.rb:16:in `initialize'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `new'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:374:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:395:in `circular_call_protection'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:373:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/bundled_asset.rb:16:in `initialize'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:377:in `new'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:377:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:94:in `block in build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/caching.rb:58:in `cache_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:93:in `build_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/base.rb:287:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/index.rb:61:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:211:in `block in find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:257:in `benchmark'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:210:in `find_asset'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:119:in `block in compile'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:118:in `each'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/sprockets/manifest.rb:118:in `compile'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-rails-2.2.4/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-2.12.3/lib/rake/sprocketstask.rb:146:in `with_logger'
/Users/a/.rvm/gems/ruby-2.1.4/gems/sprockets-rails-2.2.4/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
/Users/a/.rvm/gems/ruby-2.1.4/bin/ruby_noexec_wrapper:14:in `eval'
/Users/a/.rvm/gems/ruby-2.1.4/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
We are also experiencing the same issue, rolling back coffee-script-source to 1.8.0 seems to fix the problem. Unfortunately running our tests on a local machine seems to work fine, but fails consistently on our CI server for this issue.
Running task rake spec:javascripts, RAILS_ENV=test
rake aborted!
Capybara::Poltergeist::JavascriptError: One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).
Error: ExecJS::ProgramError: TypeError: Cannot set property 'root' of null
(in /var/lib/jenkins/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/gem_name-1.15.1/vendor/assets/javascripts/foo.coffee)
Error: ExecJS::ProgramError: TypeError: Cannot set property 'root' of null
(in /var/lib/jenkins/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/gem_name-1.15.1/vendor/assets/javascripts/foo.coffee)
at http://127.0.0.1:51887/assets/application.js:1
Tasks: TOP => spec:javascripts
(See full trace by running task with --trace)
I am having the same issue. Rolling back to 1.8.0 for now.
Noticed this causing sporadic failures on reactjs/react-rails also, locking to 1.8.0 for now
Can someone track down what the appropriate fix / PR for this should be?
I think https://github.com/jashkenas/coffeescript/blob/88ad059d546e97987223c847d397f99f9d51385c/src/coffee-script.coffee#L147 is causing this issue, which looks like is getting raised due to https://github.com/jashkenas/coffeescript/issues/3498
Btw, this is soon going to be experienced by a lot of people. Not sure what a good fix is.
I worked on the PR that may have caused the issue, could anyone having the issue tell me what versions of node they are running?
@vipulnsward Is there a specific reason why you believe line 147 is causing the issue? I did a test in a blank coffee file with just the following:
sandbox = null
sandbox.global = sandbox.root = sandbox.GLOBAL = sandbox
And the error when run through coffee, or compiled and run through node comes back as Cannot set property 'GLOBAL' of null which makes sense since GLOBAL would be set before root.
I did a search throughout the exported JS code from the coffee script library and there are a number of locations, both in the output and the libraries coffee script uses where root is set on an object.
If you have an example project where this error occurs, I'd be happy to look into it.
Here's a travis-ci build that demonstrates this issue:
https://travis-ci.org/reactjs/react-rails/jobs/50499450
Sorry, I'm not sure exactly what config information is helpful for you, but here's some that jumped out:
Pre-installed Ruby versions
ruby-1.9.3-p551
Pre-installed Node.js versions
v0.10.36
# ...
PhantomJS version
1.9.8
This JS is being run from Ruby, but I'm pretty sure it uses Node when it's available
@rmosolgo I downloaded that commit onto my own machine, I ensured I was using coffee-script-source 1.9.0, and ran BUNDLE_GEMFILE=gemfiles/rails_4.0_with_therubyracer.gemfile bundle exec rake test which is the only version of rake test that was failing, when using other BUNDLE_GEMFILEs it worked fine.
I saw the error Cannot set property 'root' of null occur. I went into the coffee-script-source gem and changed the part of the JS file where it says: l.global=l.root=l.GLOBAL=l to l.global=l.fake=l.GLOBAL=l. I re-ran the test and got the same exact error stating that root could not be set. What this means is the area of the code specified in coffee-script is not causing the error, the error is occurring somewhere else in either turbolinks or somewhere else in coffee-script.
If I have some time later today/tomorrow I'll try and hunt down where in the code the issue is occurring.
@jashkenas just to keep you in the loop, the error that is occurring is not associated with my commit, but I will try and solve it later today/tomorrow.
So, I believe I figured out the problem. I did some tests manually updating the coffee-script-source gem's coffee-script.js file. What I noticed is the supplied browser supported JS file for coffee-script didn't match the compiled output of the 1.9.0 coffee files. When I recompiled the JS files and replaced the ones supplied in coffee-script-source the error no longer occurred.
So I put in a PR with @jashkenas, hopefully this will get merged in ASAP and coffee-script-source will need to update to the latest compiled browser file.
I don't maintain coffee-script-source. You'll have to ask @sstephenson to help you out.
I'm still experiencing this error using coffee-script-source 1.9.1 and Rails 4.2.1.rc1. I'm using therubyracer 0.12.1 to compile CS and coffee-rails 4.1.0. FWIW, I'm not using Turbolinks. (Turbolinks was mentioned above.)
Same error, going back to 1.8.0 fixed it for me:
# TODO: https://github.com/jashkenas/coffeescript/issues/3829
gem "coffee-script-source", "~> 1.8.0"
It might depend on node version.
Using CoffeeScript 1.9.1 with node v0.10.12 (or 29), I can reproduce the problem. But with node v0.12, I can't.
Just putting this out there for reference of what I did for testing (since my pull was referenced as being a possible culprit of the problem). When I ran the tests within react-rails I had gotten the problem, you can see I stated this in one of my comments above. I was able to reproduce the error in all versions of node (0.8.28, 0.10.36, and 0.11.14 at the time).
To stop the error from happening I had downloaded the master repo of coffee-script, compiled a new coffee-script JS file, and replaced the distributed JS file within coffee-script-source. This fixed the problem for me.
When I looked throughout the JS library I had found that there were references to root being set on an object that didn't exist in the CS source code, this makes me think that when CS is compiled into a JS library it's injecting code to ensure it works in many different environments (maybe they are polyfills, I didn't have enough time to research it). In any case, when I compiled the source code from scratch I didn't receive the error anymore.
It's interesting to hear that node 0.12 stopped the error from occurring, when looking into the problem I had wondered if the error was actually a node error and not CS at all.
Pinging @josh ... who might be able to rebuild the gem.
This error happened as well within coffee-rails wrapper using therubyracer 0.12.1 as JS runtime
EDIT: I switched to coffee-script 1.8.0 and this did not occurred again so far
I can't seem to reproduce any of the combinations here.
gem 'execjs', '2.3.0'
gem 'coffee-script', '2.3.0'
gem 'coffee-script-source', '1.9.1'
gem 'therubyracer', '0.12.1' # with or without
$ node -v
v0.12.0
You're welcome to open any issues like this on https://github.com/josh/ruby-coffee-script/issues or move this one over there if you'd like.
I can also make sure Script and vm are marked as undefined in ExecJS when running under node to normalize the environment if that would help.
Okay, I've got some more info. In my case, the issue seems to be tied to using therubyracer. If I precompile the Rails assets with therubyracer like so:
RAILS_ENV=staging EXECJS_RUNTIME=RubyRacer rake assets:precompile
then I get error mentioned at the top of the thread above: V8::Error: Cannot set property 'root' of null. However, if I tell it to use the latest Node (0.12.0) when precompiling, then it works fine:
RAILS_ENV=staging EXECJS_RUNTIME=Node rake assets:precompile
N.B. I am clobbering the assets between precompiles, so that it happens from scratch every time.
I'm using the latest JS/CS gems, and testing under Rails 4.2.1.rc2
$ bundle show | grep 'coffee-script-source\|execjs\|therubyracer\|libv8'
* coffee-script-source (1.9.1)
* execjs (2.3.0)
* libv8 (3.16.14.7)
* therubyracer (0.12.1)
Is it a known issue that .coffee don't build under some combination of the gems above?
Two cents, as I also just got this error.
Using coffee-script-source 1.8.0 (was 1.9.1)
Using execjs 2.3.0
Using coffee-script 2.3.0
Using coffee-rails 3.2.2
Using react-source 0.12.2
Using react-rails 0.12.2.0