leesei / heroku-buildpack-casperjs

This is a Heroku buildpack of CasperJS / PhantomJS.
42 stars 40 forks source link

Can't open '/app/bin/bootstrap.js' #8

Open snoblenet opened 9 years ago

snoblenet commented 9 years ago

I have installed PhantomJS and CasperJS locally on Mac OS X using Homebrew.

In rails console, I get:

Loading development environment (Rails 4.2.0)
[1] pry(main)> `phantomjs --version`
=> "1.9.8\n"
[2] pry(main)> `casperjs`
=> "CasperJS version 1.1.0-beta3 at /usr/local/Cellar/casperjs/1.1-beta3/libexec, using phantomjs version 1.9.8\nUsage: casperjs [options] script.[js|coffee] [script argument [script argument ...]]\n       casperjs [options] test [test path [test path ...]]\n       casperjs [options] selftest\n       casperjs [options] __selfcommandtest\n\nOptions:\n\n--verbose   Prints log messages to the console\n--log-level Sets logging level\n--help      Prints this help\n--version   Prints out CasperJS version\n--engine=name Use the given engine. Current supported engine: phantomjs and slimerjs\n\nRead the docs http://docs.casperjs.org/\n\nUnsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/local/Cellar/casperjs/1.1-beta3/libexec/bin/bootstrap.js. Domains, protocols and ports must match.\n\n"
[3] pry(main)> 

I have tried to replicate this on Heroku using the following .buildpacks file:

https://github.com/leesei/heroku-buildpack-casperjs.git
https://github.com/heroku/heroku-buildpack-ruby.git

This is enabled by the multi buildpack:

steven$ heroku buildpacks --app testivate
=== testivate Buildpack URL
https://github.com/ddollar/heroku-buildpack-multi.git

However, in heroku run console --app testivate I get:

irb(main):001:0> `phantomjs --version`
=> "1.9.8\n"
irb(main):002:0> `casperjs`
Can't open '/app/bin/bootstrap.js'
=> ""
irb(main):003:0> 
irb(main):004:0* `echo $PATH`
=> "/app/vendor/bundle/ruby/2.1.0/bin:/app/bin:/app/vendor/bundle/bin:/usr/local/bin:/usr/bin:/bin:/app/vendor/phantomjs/bin:/app/vendor/casperjs/bin\n"
irb(main):005:0> 

I have tried:

steven$ heroku run bash --app testivate
Running `bash` attached to terminal... up, run.1132
Add phantomjs/casperjs paths ...
~ $ ln -sf `pwd`/bin/casperjs /usr/local/bin/casperjs
ln: creating symbolic link `/usr/local/bin/casperjs': Read-only file system
~ $ 

But to no avail.

Your thoughts?

Thanks.

leesei commented 9 years ago

I haven't tried this use case. I think the CWD (current working directory) of irb is /app/bin. And casperjs expects CWD as /app/vendor/casperjs/bin, which is the default in console call (the path of executable) but not in irb. Please try changing CWD in irb.

snoblenet commented 9 years ago

Thanks.

I get:

~ $ pwd
/app
~ $ cd vendor/casperjs/bin
~/vendor/casperjs/bin $ casperjs
Can't open '/app/bin/bootstrap.js'

Did I understand you correctly?

Interesting the PhantomJS still works (as does Ruby for that matter) -- it's just a CasperJS fail

snoblenet commented 9 years ago

Though ideally you'd want your local environment to work in the same way as Heroku. And locally I get:

[1] pry(main)> `vendor/casperjs/bin/casperjs`
bin/rails: No such file or directory - vendor/casperjs/bin/casperjs
=> nil
[2] pry(main)> `casperjs`
=> "CasperJS version 1.1.0-beta3 at /usr/local/Cellar/casperjs/1.1-beta3/libexec, using phantomjs version 1.9.8\nUsage: casperjs [options] script.[js|coffee] [script argument [script argument ...]]\n       casperjs [options] test [test path [test path ...]]\n       casperjs [options] selftest\n       casperjs [options] __selfcommandtest\n\nOptions:\n\n--verbose   Prints log messages to the console\n--log-level Sets logging level\n--help      Prints this help\n--version   Prints out CasperJS version\n--engine=name Use the given engine. Current supported engine: phantomjs and slimerjs\n\nRead the docs http://docs.casperjs.org/\n\nUnsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/local/Cellar/casperjs/1.1-beta3/libexec/bin/bootstrap.js. Domains, protocols and ports must match.\n\n"
[3] pry(main)> 
leesei commented 9 years ago

Ya, that's weird. I see nothing wrong with the setup, at least that's how I setup my local environment.

On Tue, Jun 2, 2015 at 9:39 AM, Steven Noble notifications@github.com wrote:

Though ideally you'd want your local environment to work in the same way as Heroku. And locally I get:

[1] pry(main)> vendor/casperjs/bin/casperjs bin/rails: No such file or directory - vendor/casperjs/bin/casperjs => nil [2] pry(main)> casperjs => "CasperJS version 1.1.0-beta3 at /usr/local/Cellar/casperjs/1.1-beta3/libexec, using phantomjs version 1.9.8\nUsage: casperjs [options] script.[js|coffee] [script argument [script argument ...]]\n casperjs [options] test [test path [test path ...]]\n casperjs [options] selftest\n casperjs [options] __selfcommandtest\n\nOptions:\n\n--verbose Prints log messages to the console\n--log-level Sets logging level\n--help Prints this help\n--version Prints out CasperJS version\n--engine=name Use the given engine. Current supported engine: phantomjs and slimerjs\n\nRead the docs http://docs.casperjs.org/\n\nUnsafe JavaScript attempt to access frame with URL about:blank from frame with URL file:///usr/local/Cellar/casperjs/1.1-beta3/libexec/bin/bootstrap.js. Domains, protocols and ports must match.\n\n" [3] pry(main)>

— Reply to this email directly or view it on GitHub https://github.com/leesei/heroku-buildpack-casperjs/issues/8#issuecomment-107769226 .

snoblenet commented 9 years ago

Sorry I seem to have lost one of my comments. I now have it working on Heroku as per your advice, but not in the way I use it locally.

On Heroku I now get:

Loading production environment (Rails 4.2.0)
irb(main):001:0> `vendor/casperjs/bin/casperjs`
=> "CasperJS version 1.1.0-beta3 at /app/vendor/casperjs, using phantomjs version 1.9.8\nUsage: casperjs [options] script.[js|coffee] [script argument [script argument ...]]\n       casperjs [options] test [test path [test path ...]]\n       casperjs [options] selftest\n       casperjs [options] __selfcommandtest\n\nOptions:\n\n--verbose   Prints log messages to the console\n--log-level Sets logging level\n--help      Prints this help\n--version   Prints out CasperJS version\n--engine=name Use the given engine. Current supported engine: phantomjs and slimerjs\n\nRead the docs http://docs.casperjs.org/\n\n"
irb(main):002:0> 
leesei commented 9 years ago

Great. The gist is to set BOTH phantomjs and casperjs's path to the environment. See casperjs.sh.

On Tue, Jun 2, 2015 at 9:44 AM, Steven Noble notifications@github.com wrote:

Sorry I seem to have lost one of my comments. I now have it working on Heroku as per your advice, but not in the way I use it locally.

On Heroku I now get:

Loading production environment (Rails 4.2.0) irb(main):001:0> vendor/casperjs/bin/casperjs => "CasperJS version 1.1.0-beta3 at /app/vendor/casperjs, using phantomjs version 1.9.8\nUsage: casperjs [options] script.[js|coffee] [script argument [script argument ...]]\n casperjs [options] test [test path [test path ...]]\n casperjs [options] selftest\n casperjs [options] __selfcommandtest\n\nOptions:\n\n--verbose Prints log messages to the console\n--log-level Sets logging level\n--help Prints this help\n--version Prints out CasperJS version\n--engine=name Use the given engine. Current supported engine: phantomjs and slimerjs\n\nRead the docs http://docs.casperjs.org/\n\n" irb(main):002:0>

— Reply to this email directly or view it on GitHub https://github.com/leesei/heroku-buildpack-casperjs/issues/8#issuecomment-107769641 .

snoblenet commented 9 years ago

Added a convenience method to my app to account for CasperJS behaving differently on localhost vs Heroku:

class Casper
  def self.run(file, *variable)
    base = Rails.env.production? ? "vendor/casperjs/bin/casperjs" : "casperjs"
    `#{base} #{file} #{variable}`
  end
end

BTW, I think the issue might be something to do with permissions? In that it says it can't open bootstrap.js, not that it can't find bootstrap.js.

Anyway, I haven't closed this because someone else might chime in with a solution, but for now this hack is working for me. Cheers.

leesei commented 8 years ago

https://neosmart.net/wiki/mbr-boot-process/