thlorenz / proxyquire

🔮 Proxies nodejs require in order to allow overriding dependencies during testing.
MIT License
2.75k stars 100 forks source link

Object.defineProperty called on non-object #128

Closed mfowlewebs closed 8 years ago

mfowlewebs commented 8 years ago

Hi. I'm trying to help Sails get Proxy Protocol support by using Proxyquire to proxy in the HTTP modules. I have a little demo project for the attempt.

Alas Proxyquire is giving me an error:

TypeError: Object.defineProperty called on non-object
    at Function.defineProperty (native)
    at forEachOwnPropertyName (/home/mfowle/src/sails-proxywrap/node_modules/merge-descriptors/index.js:56:12)
    at Array.forEach (native)
    at merge (/home/mfowle/src/sails-proxywrap/node_modules/merge-descriptors/index.js:48:35)
    at fill (/home/mfowle/src/sails-proxywrap/node_modules/fill-keys/index.js:9:5)
    at fillKeys (/home/mfowle/src/sails-proxywrap/node_modules/fill-keys/index.js:18:10)
    at Proxyquire._require (/home/mfowle/src/sails-proxywrap/node_modules/proxyquire/lib/proxyquire.js:153:7)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/home/mfowle/src/sails-proxywrap/node_modules/finalhandler/index.js:16:12)
    at Module._compile (module.js:541:32)

Apologies in advance if there's already a well documented reason why I ought expect this!

bendrucker commented 8 years ago

You're missing require statements:

https://github.com/mfowlewebs/sails-proxywrap/blob/55b1d3dd48fcff6506bc2cbeef599d711d3f6a1e/sails-proxywrap.js#L5-L6

http: require('proxywraphttp')
// ...
bendrucker commented 8 years ago

You're basically trying to replace the whole http module with a string and proxyquire is choking on it

mfowlewebs commented 8 years ago

Yup! Mercy be, thanks thanks thanks. Really appreciate the help.