martyjs/marty

webpack, babel, karma & marty v0.9.17 problem with requiring react

Closed this issue · 5 comments

Hi there,

I'm getting an this error on this line;

TypeError: 'undefined' is not an object (evaluating 'React.PropTypes.object')

In my code I use require('react/addons') but in marty it's using require('react') which webpack can't seem to resolve. If i change that line to require('react/addons') it works.

This only happens when running in karma. Here is the config

Any ideas ?

Cheers

I don't remember for sure, but i had this issues when i was loading multiple versions of react by accident,
but in your case, React is a Peerdependency of marty, so if your project has react as dependency, only that version would be used. facebook/react#2402,

so check how your dependencies are set up within your project,
because if your own project u should just use react/addons, because the evaluation of proptypes is a part of the react addons. u don't need it in production though.

hope this helps a bit

Thanks for the suggestion. I did a search within my node_modules for react and found only these cant see duplicate react versions

I created a test repo using the marty-todomvc demonstrating this issue

https://github.com/bulkan/marty-webpack-karma-bug

If you install marty@latest the test will pass

taion commented

Thanks for the repro. This is because you have '.' in moduleDirectories, so Marty's react.js there tries to circularly import itself.

In general it's best not to do that, and to always explicitly specify local (i.e. non-node_module) dependencies as './file'.

Thanks @taion that was it !