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

Created on 12 Dec 2016  Β·  28Comments  Β·  Source: facebook/react

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.

Most helpful comment

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

All 28 comments

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.

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

This is everything that installs as a react component:

β”œβ”€β”¬ [email protected] 
β”‚ β”œβ”€β”¬ [email protected] 
β”‚ β”‚ β”œβ”€β”€ [email protected] 
β”‚ β”‚ β”œβ”€β”¬ [email protected] 
β”‚ β”‚ β”‚ └── [email protected] 
β”‚ β”‚ └── [email protected] 
β”‚ β”œβ”€β”¬ [email protected] 
β”‚ β”‚ └── [email protected] 
β”‚ └── [email protected] 
β”œβ”€β”€ [email protected] 
β”œβ”€β”€ [email protected] 
β”œβ”€β”¬ [email protected] 
β”‚ └─┬ [email protected] 
β”‚   └─┬ [email protected] 
β”‚     └─┬ [email protected] 
β”‚       β”œβ”€β”€ [email protected] 
β”‚       β”œβ”€β”¬ [email protected] 
β”‚       β”‚ β”œβ”€β”€ [email protected] 
β”‚       β”‚ β”œβ”€β”€ [email protected] 
β”‚       β”‚ └─┬ [email protected] 
β”‚       β”‚   β”œβ”€β”€ [email protected] 
β”‚       β”‚   β”œβ”€β”€ [email protected] 
β”‚       β”‚   └── [email protected] 
β”‚       β”œβ”€β”€ [email protected] 
β”‚       β”œβ”€β”€ [email protected] 
β”‚       └── [email protected] 
β”œβ”€β”¬ [email protected] 
β”‚ β”œβ”€β”€ [email protected] 
β”‚ └─┬ [email protected] 
β”‚   └─┬ [email protected] 
β”‚     └── [email protected] 
β”œβ”€β”¬ [email protected] 
β”‚ β”œβ”€β”€ [email protected] 
β”‚ β”œβ”€β”€ [email protected] 
β”‚ └── [email protected] 
β”œβ”€β”¬ [email protected] 
β”‚ β”œβ”€β”¬ [email protected] 
β”‚ β”‚ └─┬ [email protected] 
β”‚ β”‚   └── [email protected] 

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

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

The problem is probably with your use of [email protected], which depends on [email protected]. You are installing two versions of React, one of which is incompatible with the installed version of react-dom.

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.

@designermonkey

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

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.

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.

Maybe you're using a custom npm registry that's broken, or your npm cache is invalid?
The file exists in [email protected]: https://unpkg.com/[email protected]/lib/ReactPerf.js

So somehow you have an old version of it.

I'll close as the error is demonstrably caused by a wrong npm package or a bundler.
The file does exist in [email protected].
Please let me know if I'm wrong or missed something.

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.

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!

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

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 https://github.com/facebook/react/issues/8392.

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

Thanks man.

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

Seams that this is a brunch issue. Check out this thread https://github.com/brunch/brunch/issues/1591

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!

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

@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.

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

I'm not sure this is because of that conditional require: https://github.com/brunch/brunch/issues/1591#issuecomment-270742503.

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. (https://github.com/brunch/brunch/issues/1591#issuecomment-270742503)

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

Thanks guys!

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)

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

Was this page helpful?
0 / 5 - 0 ratings