Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7593243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T21:07:13+00:00 2026-05-30T21:07:13+00:00

I’d like to execute some d3 code from the command line. Initially I just

  • 0

I’d like to execute some d3 code from the command line. Initially I just tried something like:

task 'data', 'Build some data with d3', ->
      d3 = require('lib/d3.v2')
      console.log "d3 version = "+ d3.version

But this didn’t work. I got errors like this:

node.js:201
        throw e; // process.nextTick error, or 'error' event on first tick
          ^
ReferenceError: CSSStyleDeclaration is not defined
    at /Users/mydir/Documents/classes/middleclass/app/lib/d3.min.js:1:21272
    at Object.<anonymous> (/Users/mydir/Documents/classes/middleclass/app/lib/d3.min.js:2:25395)
    at Module._compile (module.js:432:26)
    at Object..js (module.js:450:10)
    at Module.load (module.js:351:31)
    at Function._load (module.js:310:12)
    at Module.require (module.js:357:17)
    at require (module.js:368:17)
    at Object.action (/Users/mydir/Documents/classes/middleclass/Cakefile:22:10)
    at /usr/local/lib/node_modules/coffee-script/lib/coffee-script/cake.js:39:26

So…I figured this exception was telling me that I need to execute d3 inside of a browser. I tried this in a couple different ways. Basically though, I thought if I just fired up phantomjs I’d probably be able to do what I wanted to do. Here was my Cakefile:

task 'data2', 'Build some data with d3', ->
  hem = spawn 'hem', ['server']
  phantom = require('phantom')
  phantom.create (ph) ->
    ph.createPage (page) ->
      page.open 'http://localhost:9294/sandbox.html', (status) ->
        page.evaluate (-> window), (window) ->
          require = window.require
          require('lib/d3.v2')
          console.log("d3 version = "+ d3.version)
          ph.exit()
          hem.kill()

When I go this route though, I always end up getting exceptions like this:

TypeError: object is not a function
    at Object.CALL_NON_FUNCTION (native)
    at Object.<anonymous> (/Users/mydir/Documents/classes/middleclass/Cakefile:52:13)
    at Object.<anonymous> (/Users/mydir/Documents/classes/middleclass/node_modules/phantom/node_modules/dnode-protocol/index.js:274:16)
    at apply (/Users/mydir/Documents/classes/middleclass/node_modules/phantom/node_modules/dnode-protocol/index.js:143:17)
    at EventEmitter.handle (/Users/mydir/Documents/classes/middleclass/node_modules/phantom/node_modules/dnode-protocol/index.js:120:13)
    at /Users/mydir/Documents/classes/middleclass/node_modules/phantom/node_modules/dnode-protocol/index.js:81:20
    at EventEmitter.<anonymous> (/Users/mydir/Documents/classes/middleclass/node_modules/phantom/node_modules/dnode/node_modules/lazy/lazy.js:62:13)
    at EventEmitter.<anonymous> (/Users/mydir/Documents/classes/middleclass/node_modules/phantom/node_modules/dnode/node_modules/lazy/lazy.js:46:19)
    at EventEmitter.emit (events.js:67:17)
    at EventEmitter.<anonymous> (/Users/mydir/Documents/classes/middleclass/node_modules/phantom/node_modules/dnode/node_modules/lazy/lazy.js:46:39)

What am I doin wrong??


Thanks to mbostock I got the following working:

My package.json:

{
    "name": "app",
    "version": "0.0.1",
    "dependencies": {
        "d3": "~2.8.0",
        "jsdom": "~0.2.13"
    }
}

My Cakefile:

task 'd3', 'Do something with d3', ->
  jsdom = require('jsdom')
  jsdom.env({
    html: 'public/sandbox.html'
    done: (errors,window) ->
      require('d3/index.js')
      console.log("d3 version = "+ d3.version)
  })
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T21:07:14+00:00Added an answer on May 30, 2026 at 9:07 pm

    See D3’s package.json. More specifically, the file you want to require when running inside Node or similar environments is index.js rather than d3.v2.js; this file contains some special patches that make D3 compatible with the require operator.

    To try it out for yourself, cd to the d3 repository, run node to create an interactive shell, and then say

    var d3 = require("./");
    

    Or, if you’re in your own project folder, if you’ve installed D3 into node_modules/d3 via npm (npm install d3), you can say:

    var d3 = require("d3");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have just tried to save a simple *.rtf file with some websites and
I have some data like this: 1 2 3 4 5 9 2 6
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to count the length of a string with PHP. The string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.