glenjamin / skin-deep

Test assertion helpers for use with React's shallowRender test utils
MIT License
200 stars 40 forks source link

Error: Cannot resolve module 'react/lib/ReactContext' #10

Closed hallister closed 9 years ago

hallister commented 9 years ago

I'm getting this error running 0.14.0-rc1 which is particularly odd since the line its arguing is executing should never happen:

ERROR in ./~/skin-deep/skin-deep.js
Module not found: Error: Cannot resolve module 'react/lib/ReactContext' in /home/hallister/Projects/testing/node_modules/skin-deep
 @ ./~/skin-deep/skin-deep.js 25:21-54

It has no impact on tests but I find it odd that a conditional require is executing when the condition is false.

glenjamin commented 9 years ago

Are you webpack-bundling your tests? You'd need to exclude that require to silence that warning

hallister commented 9 years ago

Yes I am and that didn't even occur to me. Thanks!

glenjamin commented 9 years ago

If it was node requiring it would have just blown up :)

mohanzhang commented 8 years ago

Hey @hallister - I'm having a similar issue over at #15, and was wondering how you excluded that module? I am pretty new to testing with karma/webpack/react and my naive attempts have not been successful, and would be very grateful for some direction. Thanks!

mohanzhang commented 8 years ago

As @glenjamin mentions in #15, using webpack's IgnorePlugin worked for me!

reintroducing commented 8 years ago

Hello, I'm a Browserify user and I'm getting this error as well:

28 10 2015 16:37:21.079:ERROR [framework.browserify]: bundle error
28 10 2015 16:37:21.080:ERROR [framework.browserify]: Error: Cannot find module 'react/lib/ReactContext' from '/Users/mprzybylski/Work/SpotHero/SpotHero-Django/node_modules/skin-deep'

Any ideas?

glenjamin commented 8 years ago

You'll need to add whatever the equivalent browserify config is to exclude that import.

reintroducing commented 8 years ago

Got it, thanks. For anyone curious, I had to add this to my karma config:

browserify: {
    debug: true,
    configure: function(bundle) {
        bundle.exclude('react/lib/ReactContext');
    }
}
mesozoic-technology commented 8 years ago

What is the line for doing this w/ Webpack? I've tried it with

new webpack.IgnorePlugin('react/lib/ReactContext'),

in my webpack config, and it didn't work. Tried it without quotes, too. Thanks for any help.

glenjamin commented 8 years ago

@realisation the IgnorePlugin takes a regex as it's argument https://webpack.github.io/docs/list-of-plugins.html#ignoreplugin

I'm going to add examples into a new troubleshooting section in the readme