Skip to content
This repository has been archived by the owner on Dec 9, 2018. It is now read-only.

contextify doesn't build properly with npm install #3

Closed
jesseditson opened this issue Sep 2, 2011 · 9 comments
Closed

contextify doesn't build properly with npm install #3

jesseditson opened this issue Sep 2, 2011 · 9 comments

Comments

@jesseditson
Copy link

$ sudo npm install

> [email protected] preinstall /path/to/node/stuff/node_modules/contextify
> node-waf clean || true; node-waf configure build

'clean' finished successfully (0.014s)
Setting srcdir to                        : /path/to/node/stuff/node_modules/.npm/contextify/0.0.4/package 
Setting blddir to                        : /path/to/node/stuff/node_modules/.npm/contextify/0.0.4/package/build 
Checking for program g++ or c++          : /usr/bin/g++ 
Checking for program cpp                 : /usr/bin/cpp 
Checking for program ar                  : /usr/bin/ar 
Checking for program ranlib              : /usr/bin/ranlib 
Checking for g++                         : ok  
Checking for node path                   : not found 
Checking for node prefix                 : ok /usr/local/Cellar/node/0.4.5 
'configure' finished successfully (0.043s)
Waf: Entering directory `/path/to/node/stuff/node_modules/.npm/contextify/0.0.4/package/build'
[1/2] cxx: src/contextify.cc -> build/default/src/contextify_1.o
[2/2] cxx_link: build/default/src/contextify_1.o -> build/default/contextify.node
Waf: Leaving directory `/path/to/node/stuff/node_modules/.npm/contextify/0.0.4/package/build'
'build' finished successfully (0.370s)

the node_modules build folder now has:

.wafpickle-7 c4che config.log default

and the default folder has:

contextify.node src

note the package/build directory doesn't have a Release folder.

the package sets up using this js:

try {
    module.exports = require('../build/default/contextify').wrap;
} catch (e) {
    module.exports = require('../build/Release/contextify').wrap;
}

it appears to be failing to find contextify, (the only file in the default folder is called contextify.node), then defaulting to the Release folder, which doesn't exist.

@brianmcd
Copy link
Owner

brianmcd commented Sep 2, 2011

What's the actual error you're getting? *.node files are what C++ addons are compiled into, and that's the correct target of the require statement. If that file exists in default, the first require statement should succeed.

The default vs. Release stuff is because node 0.4.x puts things in default, and 0.5.x puts things in Release. There's probably a way to control it with waf, but I haven't looked into it yet.

@brianmcd
Copy link
Owner

brianmcd commented Sep 2, 2011

I got linked to your StackOverflow question (http://stackoverflow.com/questions/7262251/npm-doesnt-build-contextify-release-node-path-not-found/7276320#7276320). If I'm understanding the question correctly, it looks like you're trying to build Contextify on one machine, then transfer it to another? That can be tricky, since Contextify is a C++ addon. You'll need to at least make sure that both machines are running the exact same version of node and are on the same architecture. I don't know if there are other factors that could cause incompatibility.

Does Contextify build properly on the machine that you're trying to run it on? You can check out the git repository and run "node-waf configure build" in the base Contextify directory, and see if it compiles correctly. If you have nodeunit on that machine, you can run the tests with "nodeunit test/".

@jesseditson
Copy link
Author

That clears up a few things, thanks! - I have a local version of Centos that I can run the tests and build in - I'll update in a bit when I've finished that.

@jesseditson
Copy link
Author

Ok, so I tried the following:

I installed a fresh version of node and npm on my CentOS test box, ran npm install, then commented out the try/catch, so that it would show me the error it was getting trying to include default/contextify.node.

that gave me this error instead:

node.js:134
        throw e; // process.nextTick error, or 'error' event on first tick
        ^
Error: /path/to/node/node_modules/.npm/contextify/0.0.4/package/build/default/contextify.node: invalid ELF header
    at Object..node (module.js:414:11)
    at Module.load (module.js:334:31)
    at Function._load (module.js:293:12)
    at require (module.js:346:19)
    at Object.<anonymous> (/path/to/node/node_modules/.npm/contextify/0.0.4/package/lib/contextify.js:2:22)
    at Module._compile (module.js:402:26)
    at Object..js (module.js:408:10)
    at Module.load (module.js:334:31)
    at Function._load (module.js:293:12)
    at require (module.js:346:19)

so, I tried backing up the node_modules folder, then running npm install - that gave me this error:


# npm install
npm ERR! Error: EAFNOSUPPORT, Address family not supported by protocol
npm ERR!     at net.js:730:19
npm ERR!     at dns.js:196:34
npm ERR!     at IOWatcher.callback (dns.js:74:15)
npm ERR! Report this *entire* log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <[email protected]>
npm ERR! 
npm ERR! System Linux 2.6.18-238.19.1.el5
npm ERR! command "node" "/root/local/node/bin/npm" "install"
npm ERR! cwd /path/to/node
npm ERR! node -v v0.4.11
npm ERR! npm -v 1.0.27
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /path/to/node/npm-debug.log
npm not ok

@jesseditson
Copy link
Author

Also, I tried checking out and building and testing contextify. Here are the results of node-waf configure build:

Setting srcdir to                        : /root/src/contextify 
Setting blddir to                        : /root/src/contextify/build 
Checking for program g++ or c++          : /usr/bin/g++ 
Checking for program cpp                 : /usr/bin/cpp 
Checking for program ar                  : /usr/bin/ar 
Checking for program ranlib              : /usr/bin/ranlib 
Checking for g++                         : ok  
Checking for node path                   : not found 
Checking for node prefix                 : ok /root/local/node 
'configure' finished successfully (0.026s)
Waf: Entering directory `/root/src/contextify/build'
[1/2] cxx: src/contextify.cc -> build/default/src/contextify_1.o
[2/2] cxx_link: build/default/src/contextify_1.o -> build/default/contextify.node
Waf: Leaving directory `/root/src/contextify/build'
'build' finished successfully (0.285s)

and, the results of nodeunit:

contextify
✔ basic tests - blank context
✔ basic tests - basic context
✔ basic tests - test contextified object extra properties
✔ basic tests - test undefined sandbox
✔ basic tests - test for nonexistent properties
✔ basic tests - test run with filename
✔ basic tests - test accessors on sandbox
✔ basic tests - test dispose
✔ synchronous script tests - global variables in scripts should go on sandbox
✔ synchronous script tests - sandbox properties should be globals
✔ asynchronous script tests - global variables in scripts should go on sandbox
✔ asynchronous script tests - sandbox properties should be globals
✔ test global - basic test
✔ test global - self references to the global object
✔ test global - test enumerator
✔ test global - test deleter
✔ test global - test global class name
✔ test global - test global functions
✔ test global - test global.run()
✔ test global - test global.getGlobal()
✔ test global - test global.dispose()
✔ test multiple contexts
prop1
✔ test console
✔ test exceptions - basic test
✔ test exceptions - test double dispose() - sandbox
✔ test exceptions - test double dispose - global
✔ test exceptions - test run() after dispose()
✔ test exceptions - test getGlobal() after dispose()
✔ test exceptions - test global property getter after dispose()
✔ test exceptions - test global property setter after dispose()
✔ test exceptions - test global property deleter after dispose()
✔ test global property enumerator after dispose()

OK: 92 assertions (20ms)

@jesseditson
Copy link
Author

Ok, so I'm not actually sure what fixed it, but I tried starting over again, and this time npm install went off without a hitch, and now contextify works fine - so the problem appears to be that I was compiling on a machine with a different architecture than the one I was deploying on. 🤦

Sorry for wasting your time...

@brianmcd
Copy link
Owner

brianmcd commented Sep 3, 2011

Glad you got things worked out. It wasn't a waste of time. The more info that's out there on potential issues and solutions the better.

@jesseditson
Copy link
Author

So, it didn't seem worthy of a pull request, but it may be helpful to note if the reason the 4.x.x version of contextify is not found, or if it has failed for another reason before checking for the 5.x.x version. I've added this to my local version of contextify, in place of lib/contextify.js:

try {
    module.exports = require('../build/default/contextify').wrap;
} catch (e) {
    if(e.message.match('Cannot find module')){
        module.exports = require('../build/Release/contextify').wrap;
    } else {
        throw 'Error: contextify was found, but does not appear to be built in this environment. Please rebuild contextify.';
    }
}

Let me know if you would like me to fork & pull request this. Thanks!

Jesse

@brianmcd
Copy link
Owner

brianmcd commented Sep 7, 2011

Hey Jesse,

That's a good idea with the extra feedback in contextify.js. I was able to fix the wscript file so contextify always builds to the Release folder, so I just pushed v0.0.5 with that fix, plus better feedback if the require fails. I thanked you in the commit log. Also, thanks for coming back and updating the issue - definitely appreciated.

Brian

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants