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 · 8 comments

Comments

Projects
None yet
6 participants
@damassi

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 from Rewire throws error when using ES6 Classes to Rewire throws error when using ES6 imports Apr 17, 2015

@srph

This comment has been minimized.

Show comment
Hide comment
@srph

srph Apr 26, 2015

Having the same issue as well.

srph commented Apr 26, 2015

Having the same issue as well.

@jhnns

This comment has been minimized.

Show comment
Hide comment
@jhnns

jhnns Apr 27, 2015

Owner

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

Owner

jhnns commented Apr 27, 2015

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

@jhnns

This comment has been minimized.

Show comment
Hide comment
@jhnns

jhnns Apr 27, 2015

Owner

Is React using Babel for transpiling?

Owner

jhnns commented Apr 27, 2015

Is React using Babel for transpiling?

@mikeyamadeo

This comment has been minimized.

Show comment
Hide comment
@mikeyamadeo

mikeyamadeo Apr 27, 2015

+1

Using Babel for transpiling.

mikeyamadeo commented Apr 27, 2015

+1

Using Babel for transpiling.

@jhnns

This comment has been minimized.

Show comment
Hide comment
@jhnns

jhnns Apr 27, 2015

Owner

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.

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 from Rewire throws error when using ES6 imports to rewire doesn't work with babel Apr 27, 2015

@damassi

This comment has been minimized.

Show comment
Hide comment
@damassi

damassi 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 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 Apr 27, 2015

@doctyper

This comment has been minimized.

Show comment
Hide comment
@doctyper

doctyper Apr 27, 2015

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

doctyper commented Apr 27, 2015

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

@JustinTulloss

This comment has been minimized.

Show comment
Hide comment
@JustinTulloss

JustinTulloss Jun 12, 2015

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

JustinTulloss commented Jun 12, 2015

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment