Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object.defineProperty called on non-object #51

Closed
IanVS opened this issue Apr 5, 2015 · 7 comments
Closed

Object.defineProperty called on non-object #51

IanVS opened this issue Apr 5, 2015 · 7 comments
Labels

Comments

@IanVS
Copy link

IanVS commented Apr 5, 2015

Hopefully this isn't just user error, since I'm new to rewire.

I am getting the following error when I change a require to a rewire:

TypeError: Object.defineProperty called on non-object
    at defineProperty (native)
    at Function.defineProperty (/mnt/sdb1/code/dev/sane/node_modules/traceur/bin/traceur.js:257:7)
    at Object.<anonymous> (/mnt/sdb1/code/dev/sane/lib/helpers/ember.js:29:8)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (/mnt/sdb1/code/dev/sane/node_modules/traceur/src/node/require.js:65:21)
    at Module.load (module.js:335:32)
    at Object.load (/mnt/sdb1/code/dev/sane/node_modules/rewire/lib/moduleEnv.js:19:18)
    at internalRewire (/mnt/sdb1/code/dev/sane/node_modules/rewire/lib/rewire.js:50:15)
    at rewire (/mnt/sdb1/code/dev/sane/node_modules/rewire/lib/index.js:11:12)
    at Object.<anonymous> (/mnt/sdb1/code/dev/sane/tests/unit/helpers/emberTest.js:4:13)

Where it seems to be failing in the module I'm requiring is here (ember.js:29:8):

  var globalPath = path.join(
      require.resolve('ember-cli')
      .replace(/\/lib\/cli\/index\.js$/, ''),
      'bin',
      'ember');

Any thoughts on what could be going wrong here? I can provide more info if you let me know what would be helpful. Thanks!

@jhnns
Copy link
Owner

jhnns commented Apr 5, 2015

Could you find out what traceur is trying to do?

Especially this line:

    at Function.defineProperty (/mnt/sdb1/code/dev/sane/node_modules/traceur/bin/traceur.js:257:7)

Currently I can't see that rewire has something to do with it.

@IanVS
Copy link
Author

IanVS commented Apr 5, 2015

All it is doing is checking for a shim and then calling the object's normal defineProperty function.

253  function defineProperty(object, name, descriptor) {
254        if (isShimSymbol(name)) {
255          name = name[symbolInternalProperty];
256        }
257        $defineProperty(object, name, descriptor);
258        return object;
259      }

I'm not sure why this would be a problem in Treaeur, because everything works fine as long as I don't use rewire. Is there anything else I can do to try to help troubleshoot?

@jhnns
Copy link
Owner

jhnns commented Apr 5, 2015

You could create a minimal test-case that produces the error. And you could also check what value targetModule.id is here.

@IanVS
Copy link
Author

IanVS commented Apr 6, 2015

Alright, I'll try to put something together in the next few days.

@IanVS
Copy link
Author

IanVS commented Apr 18, 2015

OK, it seems that this occurs if the module being rewired exports a string or a variable with a string value. Is that not a supported use of rewire?

IanVS pushed a commit to IanVS/sane that referenced this issue Apr 18, 2015
Uses npm-which to try to resolve a binary for ember first in local node_modules,
and then in parent node_modules and the user's path, the same way that a native
npm `require()` works.

More tests would be good to have, intent is to use rewire to inject process.platform
and process.cmd, but for now rewire does not work for modules
which return a simple string or variable with a string value.

See jhnns/rewire#51
@jhnns
Copy link
Owner

jhnns commented Apr 27, 2015

@IanVS are you using mocha as test runner?

@jhnns
Copy link
Owner

jhnns commented Apr 27, 2015

OK, it seems that this occurs if the module being rewired exports a string or a variable with a string value. Is that not a supported use of rewire?

Sorry, I've over-read this.

Unfortunately yes, rewiring modules that export a primitive value is not possible, because the current API needs to attach methods like __set__ and __get__ to the export. I need to clarify that in my readme.

@jhnns jhnns added the wontfix label Apr 27, 2015
@jhnns jhnns closed this as completed in 769b88f Apr 27, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants