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

Error: Cannot find module 'react-dom/lib/ReactPerf' from 'react/lib/ReactAddonsDOMDependencies.js' #8556

Closed
designermonkey opened this issue Dec 12, 2016 · 28 comments

Comments

@designermonkey
Copy link

designermonkey commented Dec 12, 2016

ReactAddonsDOMDependencies.js:29Uncaught Error: Cannot find module 'react-dom/lib/ReactPerf' from 'react/lib/ReactAddonsDOMDependencies.js'

I spotted that there was an issue with 15.4.1 regarding something like this, but this file exists. Brunch builds OK, but then fails in the browser with this error.

I don't know what version I was using prior to this where it worked :( I have tried 15.4.0 but still no luck.

@designermonkey
Copy link
Author

I got it working using 15.3.2 so something must have changed in 15.4.0 to make brunch fail.

If I can provide any more info, please ask.

@gaearon
Copy link
Collaborator

gaearon commented Dec 12, 2016

Have you updated all React-related packages to 15.4.1 or just some?

@designermonkey
Copy link
Author

This is everything that installs as a react component:

├─┬ react@15.4.1 
│ ├─┬ fbjs@0.8.6 
│ │ ├── core-js@1.2.7 
│ │ ├─┬ promise@7.1.1 
│ │ │ └── asap@2.0.5 
│ │ └── ua-parser-js@0.7.12 
│ ├─┬ loose-envify@1.3.0 
│ │ └── js-tokens@2.0.0 
│ └── object-assign@4.1.0 
├── react-addons-css-transition-group@15.4.1 
├── react-dom@15.4.1 
├─┬ react-form-elements@0.3.3 
│ └─┬ react@0.13.3 
│   └─┬ envify@3.4.1 
│     └─┬ jstransform@11.0.3 
│       ├── base62@1.1.2 
│       ├─┬ commoner@0.10.8 
│       │ ├── glob@5.0.15 
│       │ ├── q@1.4.1 
│       │ └─┬ recast@0.11.18 
│       │   ├── ast-types@0.9.2 
│       │   ├── esprima@3.1.2 
│       │   └── source-map@0.5.6 
│       ├── esprima-fb@15001.1.0-dev-harmony-fb 
│       ├── object-assign@2.1.1 
│       └── source-map@0.4.4 
├─┬ react-helmet@3.2.3 
│ ├── deep-equal@1.0.1 
│ └─┬ react-side-effect@1.0.2 
│   └─┬ fbjs@0.1.0-alpha.10 
│     └── whatwg-fetch@0.9.0 
├─┬ react-redux@4.4.6 
│ ├── hoist-non-react-statics@1.2.0 
│ ├── invariant@2.2.2 
│ └── lodash@4.17.2 
├─┬ react-router@3.0.0 
│ ├─┬ history@3.2.1 
│ │ └─┬ query-string@4.2.3 
│ │   └── strict-uri-encode@1.1.0 

Tbh, I don't know what is core and what isn't :/

@gaearon
Copy link
Collaborator

gaearon commented Dec 12, 2016

Can you please publish a standalone repo with instructions to reproduce this?
Thanks!

@billyjanitsch
Copy link
Contributor

The problem is probably with your use of react-form-elements@0.3.3, which depends on react@0.13.3. You are installing two versions of React, one of which is incompatible with the installed version of react-dom.

@designermonkey
Copy link
Author

Well, whadya know!

Thanks. I'm intrigued however to understand how a component that isn't using the form elements (it wasn't being used yet, that was next on my list), would cause this failure?

NPM and Node are still a little confusing to me.

@gaearon
Copy link
Collaborator

gaearon commented Dec 12, 2016

@designermonkey

It's hard to tell what exactly is happening without a repository demonstrating the issue.

@designermonkey
Copy link
Author

Sadly it's private and I'm under pressure to get it done. When I do, I'll get an example put together asap.

Thanks for your help guys.

@designermonkey
Copy link
Author

I spoke too soon.

Had a clear-out of node_modules this morning to start a-fresh, reinstalled it all at 15.4.1 without the forms module, and the issue has come back.

@gaearon
Copy link
Collaborator

gaearon commented Dec 13, 2016

Maybe you're using a custom npm registry that's broken, or your npm cache is invalid?
The file exists in react-dom@15.4.1: https://unpkg.com/react-dom@15.4.1/lib/ReactPerf.js

So somehow you have an old version of it.

@gaearon
Copy link
Collaborator

gaearon commented Dec 13, 2016

I'll close as the error is demonstrably caused by a wrong npm package or a bundler.
The file does exist in react-dom@15.4.1.
Please let me know if I'm wrong or missed something.

@gaearon gaearon closed this as completed Dec 13, 2016
@designermonkey
Copy link
Author

As I said in the initial comment, I know it exists. That's what's confusing about it.

I spotted that there was an issue with 15.4.1 regarding something like this, but this file exists. Brunch builds OK, but then fails in the browser with this error.

@gaearon
Copy link
Collaborator

gaearon commented Dec 13, 2016

Yea, I’m not trying to argue with you, just pointing out it’s unactionable for us so no use keeping it open. If you figure out what’s happening please post a comment 😉 . If you don’t, but manage to find some time to share a project demonstrating it I’d be happy to dive in too. Cheers!

@designermonkey
Copy link
Author

No I know, I just thought as there was an issue already about that file going missing from older builds, it may be tangibly related.

Things I've just tried:

  1. Clearing the NPM cache: problem persists.
  2. Running brunch build --production: problem goes away.

Here is a test repo: https://github.com/designermonkey/react-issue

@gaearon
Copy link
Collaborator

gaearon commented Dec 13, 2016

Thanks for reproducing case, this is very helpful.

It is either a Brunch bug or an issue with packaging.
If it’s the latter it might be related to #8392.

It’s hard to guess for now but I’ll leave this open until we confirm either.

@gaearon gaearon reopened this Dec 13, 2016
@designermonkey
Copy link
Author

Thanks man.

@kockok
Copy link

kockok commented Dec 17, 2016

I can confirm that running brunch build --production: problem goes away. Probably a brunch BUG?

@ghost
Copy link

ghost commented Dec 31, 2016

Seams that this is a brunch issue. Check out this thread brunch/brunch#1591

@ghost
Copy link

ghost commented Jan 2, 2017

The problem with brunch is conditional require. There are Notes for CommonJS at the official requirejs website. Check out this qoute:

If you have modules that are in the traditional CommonJS module format, then you can easily convert them to work with RequireJS. Not all modules will convert cleanly to the new format. Types of modules that may not convert well:

  • Modules that use conditional code to do a require call, like if(someCondition) require('a1') else require('a2');
    ...

brunch author @paulmillr also wrote:

Conditional imports are also unsupported by ECMAScript; with the import syntax.

So, what do you think about it guys?
btw, Happy New Year!

@gaearon
Copy link
Collaborator

gaearon commented Jan 3, 2017

React has had a (different) conditional require since 15.2.0, see #6830.
Why wasn’t that one problematic?

@ghost
Copy link

ghost commented Jan 3, 2017

@gaearon after some digging into it, I found that the special problem here is the fact, that ReactAddonsDOMDependencies is inside react/lib and ReactPerf & ReactTestUtils are inside react-dom/lib

I did some naive experiment by moving the conditional requires into react-dom/lib/DevTools.
And required the DevTools inside ReactAddonsDOMDependencies. And it worked!

Basically what I did..

// react-dom/lib/DevTools.js
var DevTools = {};
if (__DEV__) {
  DevTools.ReactPerf = require('ReactPerf');
  DevTools.ReactTestUtils = require('ReactTestUtils');
}
module.exports = DevTools;
// react/lib/ReactAddonsDOMDependencies.js
...
// require always. In production its just an object..
var ReactDOMDevTools = require('react-dom/lib/DevTools');
if (__DEV__) {
  exports.getReactPerf = function () {
    return ReactDOMDevTools.ReactPerf;
  };

  exports.getReactTestUtils = function () {
    return ReactDOMDevTools.ReactTestUtils;
  };
}

But I haven't created a PR because there were some dozen tests which were failing.

@ghost
Copy link

ghost commented Jan 3, 2017

Maybe the comment above will bring some value to the brunch maintainers to fix it on the brunch / deppack side.
cc @paulmillr @goshakkk @shvaikalesh @marcioj

@gaearon
Copy link
Collaborator

gaearon commented Jan 5, 2017

I'm not sure this is because of that conditional require: brunch/brunch#1591 (comment).

gaearon added a commit to gaearon/react that referenced this issue Jan 5, 2017
See facebook#8556 and brunch/brunch#1591 (comment) for context.
This appears to be a Brunch bug but we can keep a temporary fix until the next major.
gaearon added a commit to gaearon/react that referenced this issue Jan 5, 2017
See facebook#8556 and brunch/brunch#1591 (comment) for context.
This appears to be a Brunch bug but we can keep a temporary fix until the next major.
gaearon added a commit that referenced this issue Jan 5, 2017
* Add manual build fixtures

* Inject ReactDOM into ReactWithAddons from ReactWithAddons

We used to read ReactDOM as a global inside ReactAddonsDOMDependenciesUMDShim.
This didn't work in AMD environments such as RequireJS and SystemJS.

Instead, I changed it so that ReactDOM gets injected into ReactWithAddons by ReactDOM itself.
This way we don't have to try to require it (which wouldn't work because AMD doesn't handle circular dependencies well).

This means you have to load ReactDOM first before using ReactDOM-dependent addons, but this was already the case before.

This commit makes all build fixtures pass.

* Memoize ReactDOM to avoid going into require on every access

* Add Brunch fixture

* Inline requires to work around Brunch bug

See #8556 and brunch/brunch#1591 (comment) for context.
This appears to be a Brunch bug but we can keep a temporary fix until the next major.
@gaearon
Copy link
Collaborator

gaearon commented Jan 5, 2017

Should be temporarily fixed by #8686 and will be out in 15.4.2 (to be released soon).
However this is just a workaround, and a Brunch bug seems like the real issue here. (brunch/brunch#1591 (comment))

@gaearon gaearon closed this as completed Jan 5, 2017
gaearon added a commit that referenced this issue Jan 6, 2017
* Add manual build fixtures

* Inject ReactDOM into ReactWithAddons from ReactWithAddons

We used to read ReactDOM as a global inside ReactAddonsDOMDependenciesUMDShim.
This didn't work in AMD environments such as RequireJS and SystemJS.

Instead, I changed it so that ReactDOM gets injected into ReactWithAddons by ReactDOM itself.
This way we don't have to try to require it (which wouldn't work because AMD doesn't handle circular dependencies well).

This means you have to load ReactDOM first before using ReactDOM-dependent addons, but this was already the case before.

This commit makes all build fixtures pass.

* Memoize ReactDOM to avoid going into require on every access

* Add Brunch fixture

* Inline requires to work around Brunch bug

See #8556 and brunch/brunch#1591 (comment) for context.
This appears to be a Brunch bug but we can keep a temporary fix until the next major.

(cherry picked from commit ca2c71c)
@gaearon
Copy link
Collaborator

gaearon commented Jan 6, 2017

Should be fixed after updating all React packages to 15.4.2.
Please verify.

@designermonkey
Copy link
Author

Thanks guys!

@astw
Copy link

astw commented Oct 7, 2017

React 16.0.0
Uncaught Error: Cannot find module "react-dom/lib/ReactPerf"
at webpackMissingModule (index.js?afe1:1)
at eval (index.js?afe1:1)

@gaearon
Copy link
Collaborator

gaearon commented Oct 7, 2017

React 16 does not currently support the React Perf addon. Please read the 16 announcement blog post that mentions this.

@facebook facebook locked and limited conversation to collaborators Oct 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants