Environment variable in babelrc ignored by Meteor build

#1

I am trying to use babel-plugin-rewire to stub imports in my project unit tests.

I have the following babelrc at the root of my meteor project:

{
“plugins”: [
“transform-class-properties”
],
“env”: {
“test”: {
“plugins”: [
“rewire”
]
}
}
}

When I run my test using the following command:

NODE_ENV=“test” meteor test --driver-package=practicalmeteor:mocha --port 3100 --settings settings.json

I endup having this error:

Error: Cannot read property ‘Rewire’ of undefined
at Hook. (imports/server/resource/tests/mymodule.tests.js:23:9)
at run (packages/practicalmeteor:mocha-core/server.js:56:16)

If I change my babelrc to add “rewire” besides “transform-class-properties” everything works fine.

Any ideas?

Thanks,
SP

1 Like
#2

While I don’t have any particular solution, I’d say your title is definitely wrong. Babel is clearly obeying the env variable (a problem I came in here all set to solve). Instead, Babel is erroring, which needs the attention I believe of Meteor devs.

#3

You are absolutely right and I edited the title.

#4

Any progress on figuring this out? I am having the same issue.

#5

Nope wasn’t able to find a solution. I’m currently adding rewire in my babelrc when I need to run my tests. I probably get back to this later. Keep me posted if you find something.

#6

I asked about it on the meteor/babel github. It looks like it isn’t supported: https://github.com/meteor/babel/issues/14

1 Like
#7

If anyone again stumbles over this question: It’s supported now. See https://github.com/meteor/meteor/pull/8963