8

I installed casperjs for the first time and ran the sample scripts. The first sample script (javascript) ran without incident. Then i tried running a coffescript sample, which I prefer, and received the following error:

Unable to load script test.coffee; check file syntax

I searched for an answer and the solution in the only related issue didn't work for me. I was able to compile the CoffeeScript (test.coffee) into JavaScript (test.js) and then ran the compiled JavaScript, again, without indecent.

I tried to track down the error by searching for the error message in the casperjs files. I found the error message at the end the ~/.node/lib/node_modules/casperjs/bin/bootstrap.js file where it passes control to phantomjs. I created simple a CoffeeScript: test_phantomjs.coffee:

console.log "hello phantomjs"
phantom.exit()

and ran the script (phantomjs test_phantomjs.coffee) with the following result:

Can't open 'test_phantomjs.coffee'

At this point I'm at loss. The problem is more of an inconvenience than anything since compiling into JavaScript solves the issue. Is their something I'm missing?

2
  • Did you ever resolve this? I'm running into the same problem. I noticed that my script works on OSX but not Ubuntu. Commented Oct 29, 2014 at 13:44
  • Had this same issue on Phantom 1.9.0. Solved with an update to the newest version of phantomjs (1.9.8 at time of writing). Commented Nov 10, 2014 at 21:26

4 Answers 4

1

In Phantomjs2.0 was removed support of coffee-script

https://github.com/ariya/phantomjs/issues/12410

Sign up to request clarification or add additional context in comments.

Comments

1

(disclaimer: i'm/was part of contribution team) the support of coffee script in CasperJS depends on the version of phantomJs you are using because this is phantomjs that provide coffee script support out of box.

You can also use and install slimerjs (https://slimerjs.org) which - from my point of view - is more performant than phantomjs and supports coffeescript scripts.

Mickaël

Comments

0

Works for me. Can you post your PhantomJS version and platform?

Mine on Mac OS X:

$ phantomjs -v
1.9.8

Just works:

$ phantomjs test_phantomjs.coffee 
hello phantomjs

Comments

0

As others say, PhantomJS v2.x no longer supports CoffeeScript.

Therefore, now you have 2 options to run PhantomJS with CoffeeScript:

  • Run plain *.coffee files with PhantomJS v1.9.8
  • Compile *.coffee files to *.js, and run *.js with PhantomJS v2.x

I recommend the latter up-to-date way, and this is how package.json looks like:

{
    "scripts": {
        "pretest": "npm install && coffee --compile **/*.coffee",
        "test": "casperjs test --fail-fast script/*.js",
        "watch": "coffee --watch --compile **/*.coffee"
    }
}

See more detail at ymkjp/phantomjs2x_coffee_sample.

Btw, here's the way to install PhantomJS v1.9.8 on Ubuntu.

$ sudo apt-get update
$ sudo apt-get install build-essential g++ flex bison gperf ruby perl \
  libsqlite3-dev libfontconfig1-dev libicu-dev libfreetype6 libssl-dev \
  libpng-dev libjpeg-dev python libx11-dev libxext-dev git
$ cd ~
$ wget -O- https://github.com/ariya/phantomjs/archive/1.9.8.tar.gz | tar zxvf -
$ cd ~/phantomjs-1.9.8
$ bash build.sh  # It takes 30 min or so (Up to your host machine)
$ sudo ln -s ~/phantomjs-1.9.8/bin/phantomjs /usr/local/bin
$ phantomjs --version
1.9.8

Cheers.

1 Comment

I would recommend adding a watch task like this "watch": "coffee -o js/ -cw src/"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.