mapbox / node-or-tools

Node.js bindings for or-tools vehicle routing problems
MIT License
146 stars 48 forks source link

Error: Cannot find module './binding/node_or_tools.node' #44

Closed hopewise closed 6 years ago

hopewise commented 6 years ago

When I try to install the example here: https://github.com/mapbox/node-or-tools/tree/master/example I get error:

 Error: Cannot find module './binding/node_or_tools.node'
     at Function.Module._resolveFilename (module.js:325:15)
     at Function.Module._load (module.js:276:25)
     at Module.require (module.js:353:17)
     at require (internal/module.js:12:17)
     at Object.<anonymous> (/Users/samir/Downloads/node-or-tools-master/lib/index.js:1:80)
     at Module._compile (module.js:409:26)
     at Object.Module._extensions..js (module.js:416:10)
     at Module.load (module.js:343:32)
     at Function.Module._load (module.js:300:12)
     at Module.require (module.js:353:17)

although I did:

npm install

and I can see node_or_tools is already installed:

npm WARN package.json node_or_tools_example@0.0.1 No repository field.

> node_or_tools@1.0.5 install /Users/samir/Downloads/node-or-tools-master/example/node_modules/node_or_tools
> node-pre-gyp install --fallback-to-build

[node_or_tools] Success: "/Users/samir/Downloads/node-or-tools-master/example/node_modules/node_or_tools/lib/binding/node_or_tools.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile

any idea?

daniel-j-h commented 6 years ago

Looks like the example simply requires the top level dir here:

https://github.com/mapbox/node-or-tools/blob/4afc61646d54b92e274457369f66a1064d611a68/example/index.js#L21

but you have the library in your example's node_modules directory:

[node_or_tools] Success: "/Users/samir/Downloads/node-or-tools-master/example/node_modules/node_or_tools/lib/binding/node_or_tools.node"

The proper solution is to add the dependency to the example's package.json and then properly require it in the example. Not sure why we didn't do this in the first place.

What you also can do is:

hopewise commented 6 years ago

thanks, I've installed successfully now your project is very interesting! 💘