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

rewire doesn't work with babel #55

Closed
damassi opened this issue Apr 17, 2015 · 9 comments
Closed

rewire doesn't work with babel #55

damassi opened this issue Apr 17, 2015 · 9 comments

Comments

@damassi
Copy link

damassi commented Apr 17, 2015

I've just finished porting all of my React.js code to ES6 and found that my tests have broken due to Rewire (seemingly) not supporting the new syntax.

// DummyClass.js
import states from 'utils/states';

export default class DummyClass {
  constructor() {}
}

// DummyClass-spec.js
describe('Test', function() {
    it('should work', function() {
       var rewire = require('rewire');
       var DummyClass = rewire('./DummyClass');
       DummyClass.__set__('states', 'foo'); // throws ReferenceError: states is not defined
    })
});

However, when importing using var states = require('utils/states') everything is just fine.

Any assistance would be appreciated!

@damassi damassi changed the title Rewire throws error when using ES6 Classes Rewire throws error when using ES6 imports Apr 17, 2015
@srph
Copy link

srph commented Apr 26, 2015

Having the same issue as well.

@jhnns
Copy link
Owner

jhnns commented Apr 27, 2015

Yes, probably the same error as in jhnns/rewire-webpack#12

@jhnns
Copy link
Owner

jhnns commented Apr 27, 2015

Is React using Babel for transpiling?

@mikeyamadeo
Copy link

+1

Using Babel for transpiling.

@jhnns
Copy link
Owner

jhnns commented Apr 27, 2015

I can't see how this could be fixed by my side. As @sairion pointed out, babel is changing variable names. Thus all uses of eval() will not work as expected.

I hope babel will do something about it. Although eval() should not be used in day-to-day code, it is still part of the language and will not be deprecated.

@jhnns jhnns changed the title Rewire throws error when using ES6 imports rewire doesn't work with babel Apr 27, 2015
@damassi
Copy link
Author

damassi commented Apr 27, 2015

This is super disappointing as Rewire is the most useful library ever! It might be worthwhile to start a discussion with the Babel folks.

I'll go ahead and close.

@damassi damassi closed this as completed Apr 27, 2015
@doctyper
Copy link

Hm, then we may have a problem. Babel says it's not their issue: babel/babel#1337

@JustinTulloss
Copy link

For what it's worth, @speedskater has written an alternative that works with Babel's ES6 module compilation. https://github.com/speedskater/babel-plugin-rewire

@d4nyll
Copy link

d4nyll commented Sep 8, 2018

Note that babel-plugin-rewire does not currently work with Babel 7. See Babel 7 Support? #209 for more details.

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

No branches or pull requests

7 participants