Skip to content
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

Webpack tries to bundle react-addons-test-utils when it is not needed #968

Closed
donaldpipowitch opened this issue Jun 2, 2017 · 8 comments

Comments

@donaldpipowitch
Copy link

donaldpipowitch commented Jun 2, 2017

I use the newest version of enzyme, react-dom and react-test-renderer and I shouldn't need react-addons-test-utils anymore. But it looks like enzyme still requires react-addons-test-utils in webpack projects.

ERROR in ./~/enzyme/build/react-compat.js
Module not found: Error: Can't resolve 'react-addons-test-utils' in '/Users/foo/bar/node_modules/enzyme/build'
 @ ./~/enzyme/build/react-compat.js 143:20-54

I think it comes from this try/catch-block. It looks like requireing react-dom/test-utils and/or react-test-renderer/shallow fail while bundling (or: they are bundled at build time and something fails inside this try/catch at runtime), so it tries to get react-addons-test-utils. Or does webpack try to bundled things inside a catch by default?

A special handling for react-addons-test-utils in webpack projects currently isn't mentioned in the docs.

@donaldpipowitch donaldpipowitch changed the title Remaining "Shallow renderer has been moved to react-test-renderer/shallow." warning in webpack projects? Webpack tries to bundle react-addons-test-utils when it is not needed Jun 2, 2017
@donaldpipowitch
Copy link
Author

donaldpipowitch commented Jun 2, 2017

It looks like it works, if react-addons-test-utils is flagged as external in your webpack config:

{
  entry,
  output,
  // ...
  externals:  [
    'react/lib/ExecutionEnvironment',
    'react/lib/ReactContext',
    'react/addons',
    'react-addons-test-utils'  // NEW
  ]
}

@ljharb
Copy link
Member

ljharb commented Jun 2, 2017

Seems like we may need to update the docs?

@jwbay
Copy link
Contributor

jwbay commented Jun 3, 2017

Or does webpack try to bundled things inside a catch by default?

FWIW, yes. Webpack is pretty aggressive about bundling everything it thinks you need. It doesn't care what language construct the require statement is in; if it sees it, it's going to bundle the package.

@thiagodebastos
Copy link

thiagodebastos commented Jun 13, 2017

FYI these are the warnings I get when running a simple test with jest:

console.error node_modules/fbjs/lib/warning.js:36
      Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.
console.error node_modules/fbjs/lib/warning.js:36
      Warning: Shallow renderer has been moved to react-test-renderer/shallow. Update references to remove this warning.

#968 (comment) didn't help in my case.

"react-addons-test-utils": "^15.5.1"
"react": "^15.5.4"
"react-dom": "^15.5.4"

PS: Attempting to run enzyme on react@16.0.0-alpha.13 gives the bug relating to requestAnimationFrame.

@ljharb
Copy link
Member

ljharb commented Jun 13, 2017

Note that React 16 doesn't exist yet; and alphas are not supported.

@benbarber
Copy link

@thiagodebastos try removing react-addons-test-utils as a dependency and then installing react-test-renderer instead. That fixed the warnings for me when running jest.

@resting
Copy link

resting commented Sep 12, 2017

With "enzyme": "^2.9.1" and react-test-renderer": "^15.6.1" .
I get some weird console.log after the test ends.

Watch Usage
 › Press a to run all tests.
 › Press p to filter by a filename regex pattern.
 › Press t to filter by a test name regex pattern.
 › Press q to quit watch mode.
 › Press Enter to trigger a test run.
  console.log src/pages/shared/menu/collapsed.test.js:10
    ShallowWrapper {
      root: [Circular],
      unrendered: 
       { '$$typeof': Symbol(react.element),
         type: [Function: Collapsed],
         key: null,
         ref: null,
         props: {},
         _owner: null,
         _store: {} },
  ...

edit: My bad. It was from my test :)

@hansmosh
Copy link

@ljharb ljharb closed this as completed Sep 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants