Environment variable in babelrc ignored by Meteor build

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”: [
“env”: {
“test”: {
“plugins”: [

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?


1 Like

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.

You are absolutely right and I edited the title.

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

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.

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

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