I am trying to use babel-plugin-rewire for the first time, but I'm having some difficulty. I have installed it and Babel (via npm install --save-dev babel-core babel-plugin-rewire), and I've added it to my .babelrc file:
"presets": ["es2015", "react", "rewire"]
and to my Webpack config too, just for good measure:
loaders: 'babel?plugins=rewire'
Then, in my test I have the following (an attempt to rewire a postMessage function exported from a MessageQueue ,odule):
import { __RewireAPI__ as postMessage } from '~/src/store/ducks/MessageQueue'
before(() => {
__RewireAPI__.__Rewire__('postMessage', () => console.log('win!'))
});
However, I get the following error:
appHome/node_modules/babel-core/lib/transformation/file/options/option-manager.js:281
throw new Error("Couldn't find preset " + (0, _stringify2.default)(val) + " relative to directory " + (0, _stringify2.default)(dirname));
^
Error: Couldn't find preset "rewire" relative to directory "appHome/"
That error seems to suggest that I didn't install rewire, but I most certainly did, which Node confirms:
npm list | grep rewire
├── babel-plugin-rewire@1.0.0
Is there anything else I might be doing wrong to cause this? I've tried searching both on the web and through this project's issues, but I haven't seen this particular error, so I strongly suspect it's a matter of user error and not a true bug (but having never used rewire successfully before, I can't say for sure).
I am trying to use babel-plugin-rewire for the first time, but I'm having some difficulty. I have installed it and Babel (via
npm install --save-dev babel-core babel-plugin-rewire
), and I've added it to my.babelrc
file:and to my Webpack config too, just for good measure:
Then, in my test I have the following (an attempt to rewire a
postMessage
function exported from aMessageQueue
,odule):However, I get the following error:
That error seems to suggest that I didn't install
rewire
, but I most certainly did, which Node confirms:Is there anything else I might be doing wrong to cause this? I've tried searching both on the web and through this project's issues, but I haven't seen this particular error, so I strongly suspect it's a matter of user error and not a true bug (but having never used rewire successfully before, I can't say for sure).