How to install the Perl module "JavaScript" on Unix

This article deals with installing JavaScript on Unix, specifically FreeBSD. Although FreeBSD comes with a port of SpiderMonkey, in /usr/ports/lang/spidermonkey, it doesn't seem to work with the Perl JavaScript module. Following the advice given in the JavaScript module, I reinstalled the spidermonkey library myself and built against that.
  1. Download the Javascript source code from Mozilla:
  2. Unpack this file and go to the subdirectory js/src.
  3. Run the makefile like this:
    gmake -f Makefile.ref
  4. This produces an error message: config/ No such file or directory
    cat: ../../dist/FreeBSD7.2-RELEASE_DBG.OBJ/nspr/Version: No such file or directory
    gmake: *** No rule to make target `config/'.  Stop.
  5. Copy the file config/ to config/, or whatever it said in the equivalent message.
  6. Run gmake again.
  7. The output files are in the directory FreeBSD7.2-RELEASE_DBG.OBJ/.
  8. Copy the header files (*.h) and tables (*.tbl) from the src directory to the FreeBSD7.2-RELEASE_DBG.OBJ.
    [ben@mikan] src 575 $ cp *.tbl *.h FreeBSD7.2-RELEASE_DBG.OBJ/
    Note that the header file jsautocfg.h is only in the FreeBSD7.2-RELEASE_DBG.OBJ directory, so if you compile against the header files in src, you will get a huge number of errors from the C compiler, starting off with the line
    /home/ben/software/js/js/src/jstypes.h:245:71: error: jsautocfg.h: No such file or directory
  9. Set up the environment to link against the compiled library:
    export JS_LIB=/home/ben/software/js/js/src/FreeBSD7.2-RELEASE_DBG.OBJ/
    export JS_INC=/home/ben/software/js/js/src/FreeBSD7.2-RELEASE_DBG.OBJ/
  10. Run cpan to install JavaScript:
    cpan JavaScript
    In my case this required installing one prerequisite, Test::Exception. Remember that if cpan fails, you can always download the distribution from CPAN and install it with
    perl Makefile.PL
    make test
    make install

  11. Copyright © Ben Bullock 2009-2023. All rights reserved. For comments, questions, and corrections, please email Ben Bullock ( or use the discussion group at Google Groups. / Privacy / Disclaimer