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

TypeError: cannot read property 'declarations' of undefined #69

Closed
baabgai opened this issue Oct 29, 2015 · 2 comments
Closed

TypeError: cannot read property 'declarations' of undefined #69

baabgai opened this issue Oct 29, 2015 · 2 comments

Comments

@baabgai
Copy link

baabgai commented Oct 29, 2015

When exporting undefined variables, stand-alone babel <filename>.js transpiles the following just fine

export var status;

is translated to

'use strict';
Object.defineProperty(exports, "__esModule", {
  value: true
});
var status;
exports.status = status;

running the same snippet together with babel --plugins rewire <filename>.js leads to an error message

TypeError: <filename.js>: Cannot read property 'declarations' of undefined
at ..../babel-plugin-rewire.js:210:49
....

Just to give some context why somebody would export a undefined variable (it's actually not my choice). We work on a Typescript project and Typescript offers the possibility for defining enums like

export enum Status = { LOADING, SUCCESS, FAILURE }

this get's compiled from the typescript compiler into

export var Status;
(function (Status) {
  Status[Status["LOADING"] = 0] = "LOADING";
  Status[Status["SUCCESS"] = 1] = "SUCCESS";
  Status[Status["FAILURE"] = 2] = "FAILURE"; 
})(Status || (Status = {}));
;

trying to run that code through babel with rewire plugins leads to the error described above.

@speedskater
Copy link
Owner

@baabgai I think I have fixed your issue and provided a new beta version 1.0.0-beta-2. Could you please test it and if you have any issues with it could you please provide a PR with a minimal sample reproducing your error (analog to the samples in the repo used by https://github.com/speedskater/babel-plugin-rewire/blob/master/usage-tests/BabelRewirePluginUsageTest.js.)

@baabgai
Copy link
Author

baabgai commented Nov 30, 2015

Integrated the new beta into our project and everything seems to work fine now.
Thanks for the fix!

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

2 participants