-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot resolve module 'react/addons' #503
Comments
Do you have |
Are you sure you're using React 15.2.1? That if (REACT013) {
renderToStaticMarkup = React.renderToStaticMarkup;
/* eslint-disable react/no-deprecated */
findDOMNode = React.findDOMNode;
unmountComponentAtNode = React.unmountComponentAtNode;
/* eslint-enable react/no-deprecated */
TestUtils = require('react/addons').addons.TestUtils;
batchedUpdates = require('react/addons').addons.batchedUpdates;
// ...
} If you can provide a reproducible case that would be great. |
npm version react: ... version: '15.2.1', ... so they are both installed and what I mentioned earlier. From another post I figured out that I had to modify: cfg/test.js Regardless I have it working now. Thank you for your help. |
Glad to hear it! |
Wait! What fixed the react/addons bug?? |
Add to karma.conf:
|
Just an FYI on this I have a minimal use case repo which shows the errors Webpack2 Webpack1 In both cases I have to add externals: {
'jsdom': 'window',
'cheerio': 'window',
'react/lib/ExecutionEnvironment': true,
'react/addons': true,
'react/lib/ReactContext': 'window'
}, otherwise I get errors
without
|
Just in case someone in the future runs into the same problem I ran into which led me here. I had a really odd situation where I was doing a dynamic require which resulted in webpack attempting to create a bundle for my co-located test file which required enzyme and attempted to resolve the |
@kentcdodds Hello. I have the same issue but I didn't know how I can disable dynamic require in webpack 2. Because it builds my react project. How I can do that stuff like you? Could you tell me, please, how did you do that? Thanks! |
I used this "hack" to resolve that issue. My question isn't actual anymore. Thanks :) |
Thanks @kentcdodds wouldn't have found the cause without your comment. I think the reason this happens is when using a dynamic import webpack doesn't know what you will require ahead of time so it creates a bundle for every js file in the directory which your trying to import from, including test files. For anyone else who comes here with this problem, one solution is to wrap the tests in a if block so that they only run when in a test environment. This means that you'll need to use require instead of import for pulling in your dependancies. Here's an example.
|
That seems like a really inefficient solution to a webpack config flaw. Why would webpack be bundling up tests, ever? |
@ljharb, it's totally possible/reasonable for this to happen with co-located tests and dynamic requires. Don't have time to go into it right now. In any case, what I'd do instead is make it so your dynamic require couldn't possibly get to your tests. What you have there is a pretty bad hack and I wouldn't personally be satisfied if that were my "solution." I'm sure there's a way that you can configure webpack to ignore a |
@kentcdodds one of the many downsides of colocated tests is that you have to configure all your tools to be aware of them; if your webpack config doesn't skip over your colocated tests, then it's a flaw in your config. If the config can't work around it, then the solution is easy - don't colocate your tests. |
@kentcdodds, @ljharb, thanks for you feedback Note to self, don't post "solutions" when it's late in the night and you've been working on a problem for too long :) To give a little context, the app I'm working is right at beginning of development (only has 2 small test files For the record, I didn't just jump on that "solution" before trying the one's you suggested. My first instinct was to move tests out of the folder, but I find great benefit in having co-located tests so I was trying to avoid that if possible. So then I looked at configuring webpack but as far as I'm aware create-react-app doesn't enable that, so that was out. So then I looked into require.context but after digging into that some I found that it wasnt' recommended to use. I'll go with moving the tests to a different folder and call it a day. |
React: 15.2.1
ERROR in ./
/enzyme/build/react-compat.js/enzyme/build/react-compat.js 40:16-39 41:46-69Module not found: Error: Cannot resolve module 'react/addons' in ./node_modules/enzyme/build
@ ./
The text was updated successfully, but these errors were encountered: