0

When I coded the d3-composite-projections, the following stuff worked:

The directory tree:


    - composite-projections.js
    |
    |- test
    |     |- test.js
    |- node_modules

Inside test.js, I required d3.js and then, loaded composite-projections.js to test it, the following way:


    var d3 = require('../node_modules/d3/d3.js');
    var composite_projection = require('../composite-projections.js');
    ...

This worked ok, but now I've changed my machine, and running the test gives me the following error:

Message:
    d3 is not defined
Stack:
ReferenceError: d3 is not defined
    at ~/d3-composite-projections/composite-projections.js:6:1

So it's like the required d3 doesn't work when called from composite-projections.js, as if it was never included. Does somebody know why and why it used to work before?

Community
  • 1
  • 1
Roger Veciana
  • 983
  • 1
  • 12
  • 25

1 Answers1

0

Finally I solved the problem using the technique explained in this answer: Load “Vanilla” Javascript Libraries into Node.js.

It's possible to call a function passing the environment with the vm library.

Anyway, my solution used to work, which I can't understand.

Community
  • 1
  • 1
Roger Veciana
  • 983
  • 1
  • 12
  • 25