0

I'm trying to run a node script (vg2svg), but get this error:

Error: Cannot find module 'd3'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/Users/my_user/repos/vega/index.js:10:6)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

I've installed nodejs and npm with macports, and d3 with npm install d3, but d3 doesn't seem to be recognized.

When I run node from the macports dir (/opt/local/bin/) and do require("d3") there's some sensible output, but when I cd to a different dir I get that Cannot find module error again.

I've also tried a few variations on export NODE_PATH=.:/opt/local/bin/:/Users/my_user/repos/vega/ but that didn't seem to help either.

Any ideas?

ohad
  • 353
  • 3
  • 12

1 Answers1

0

If you are wanting to require a module you must do npm install you should do npm init first and both should be run from the root directory of where your project resides directory.

Jedediah Smith
  • 558
  • 4
  • 10