Question: does brunch support conditional require ? (use case in [email protected] above) #1881
Replies: 17 comments
-
I've just had a quick test with webpack doesn't have this problem, but a default config with webpack seems just packing everything in the bundle? the size is 1.4MB vs brunch can build a dev version of ~930KB; 1.7M Dec 17 23:33 build.js.map
1.4M Dec 17 23:33 build.js if (true) {
var ReactPerf = __webpack_require__(623);
... |
Beta Was this translation helpful? Give feedback.
-
it seems this project is out of maintenance? from current open issues I can see multiple ones remain open after 10+ days without any response; on community support on StackOverflow (http://brunch.io/support http://stackoverflow.com/questions/tagged/brunch) or http://ost.io/@brunch/brunch it is similar that many questions remain open for a long time; As a new user with brunch, partially convinced by http://brunch.io/docs/why-brunch#brunch-vs-webpack when brunch works I feel it works better than webpack, and the transplied vendor.js is smaller; but when it doesn't work like in #1592 #1591 #1588 #1587 #1585 #1581 #1580 #1573 the feeling is helpless, ping @paulmillr @goshakkk @shvaikalesh @marcioj as maintainers from this project's 2016 major contributors https://github.com/brunch/brunch/graphs/contributors?from=2016 I think will have to switch back to webpack if can't resolve this in another few days
I can't agree because "big folks" here is referred passively if none of those "big folks" noticed this project, why not someone here proactively push this project to front of their eyes; or like this podcast on webpack2 do some self-marketing: many kinds of evangelist can be done earlier Javascript is the most thriving community I've ever seen, on every functionality domain there are tons of projects competing each other, if you don't actively taking care of it, let it being swallowed by tons of bugs, be dying of fading out is sooner or later |
Beta Was this translation helpful? Give feedback.
-
Brunch is an open source project that is maintained in our spare time; some of the contributions are sponsored out of Paul's own pocket. You may find it hard to believe but most of us have real lives with partners and friends; as well as work or contracts that we need to pay our bills, so it's no surprise the time we have for side projects and OSS is limited and we may choose to prioritize other projects of ours. It's an open source project, not a cafe. We don't owe you—or anyone else, for that matter—a thing. You are more than welcome, however, to submit PRs and address your own questions by looking at the sources (they are all right here on GitHub!) and maybe even posting the answers here in Issues so that everyone else could see them. Pinging top contributors and demanding something shows you feel entitled. Sorry to burst your bubble but you are not entitled to anything. I personally owe you no more responding to issues than you owe me to respond to other Brunch issues here. If you like Brunch, you are always free to helps us out by tackling issues, bugs, adding features, and doing community work. In fact, that would be really awesome! ❤️🔥 If you want your project to depend on Brunch but you require support, you're more than welcome to pay for commercial-level support (it's right on the page you linked: http://brunch.io/support). Only then can you demand something... and not from all of the top contributors, but from the people that provide you support — Paul or Andriy in this case. |
Beta Was this translation helpful? Give feedback.
-
so back to this question, could you comment more on "is this a problem brunch can't handle right now?" I see this kind of conditional module loading is pretty common
|
Beta Was this translation helpful? Give feedback.
-
We don't support this. Conditional imports are also unsupported by ECMAScript; with the |
Beta Was this translation helpful? Give feedback.
-
I guess this would become big problem; since https://unpkg.com/[email protected]/lib/ReactAddonsDOMDependencies.js if (process.env.NODE_ENV !== 'production') {
var ReactPerf = require('react-dom/lib/ReactPerf');
var ReactTestUtils = require('react-dom/lib/ReactTestUtils');
[...]
} |
Beta Was this translation helpful? Give feedback.
-
We do have plans to implement this. |
Beta Was this translation helpful? Give feedback.
-
Brunch does replace The bundle will still end up containing these files, because our analyzer only detects If you want Brunch to not include these files in the production build, your PR to add that would be appreciated. |
Beta Was this translation helpful? Give feedback.
-
do you mean you cannot reproduce the issue here? from the vendor bundle, I am not seeing if ('development' !== 'production') {
var ReactPerf = require('react-dom/lib/ReactPerf'); // runtime error happened here
var ReactTestUtils = require('react-dom/lib/ReactTestUtils');
[...]
}
})();
}); |
Beta Was this translation helpful? Give feedback.
-
I'm confused. I wanted to fix this on the React side but I can still see the issue even after extracting What supports the conclusion that this was caused by a conditional require? |
Beta Was this translation helpful? Give feedback.
-
It appears that the error is not caused by the conditional require. Instead, I was able to fix it by moving Before var ReactPerf = require('react-dom/lib/ReactPerf');
var ReactTestUtils = require('react-dom/lib/ReactTestUtils');
exports.getReactPerf = function () {
return ReactPerf;
};
exports.getReactTestUtils = function () {
return ReactTestUtils;
}; After exports.getReactPerf = function () {
var ReactPerf = require('react-dom/lib/ReactPerf');
return ReactPerf;
};
exports.getReactTestUtils = function () {
var ReactTestUtils = require('react-dom/lib/ReactTestUtils');
return ReactTestUtils;
}; So it looks more like an unrelated timing bug. |
Beta Was this translation helpful? Give feedback.
-
I intend to merge a temporary workaround for this in facebook/react#8686 but it's likely we'll remove it in the next major (since this looks to be a Brunch bug rather than a problem with React). |
Beta Was this translation helpful? Give feedback.
-
right; I believe the problem is in brunch because I tested webpack with react 15.4.1 unchanged that doesn't have the problem. so it seems like the problem in brunch is not only in conditional branches, but also in all non-top level require brunch can't handle? I searched in the brunch compiled bundle code, don't see the |
Beta Was this translation helpful? Give feedback.
-
The problem might be related to a bug in handling circular dependencies or something like this. Otherwise I'm not sure why inlining requires into a function worked around the problem. |
Beta Was this translation helpful? Give feedback.
-
Hey @gaearon, sorry for the trouble & thanks for the hot fix: it will give us time to resolve the issue the right way. |
Beta Was this translation helpful? Give feedback.
-
In the meantime, this should be fixed after updating all React packages to 15.4.2. |
Beta Was this translation helpful? Give feedback.
-
The conditional cast to the window object necessary? |
Beta Was this translation helpful? Give feedback.
-
Description
What's the essence of the issue?
Expected behavior
Tell us what you think should happend.
support latest react:
Actual behavior
Tell us what actually happens.
I met a same issue as this one: error in browser console: but his solution of remove node_modules/ and re-compile doesn't resolve problem here; it is always reproduce
http://stackoverflow.com/questions/40953011/browser-console-error-cannot-find-module-react-dom-lib-reactperf-from-react
If at all possible, please create a small demo app on GitHub that demonstrates the issue so it's easier for us to check and debug.
brunch new -s react; npm install --save react@latest react-dom@latest material-ui ...
the default empty template compiles and runs fine; but once I added the first button, the ui reload failed with above error in console
Environment
package.json
contentsbrunch config contents
the default from template:
Other useful files, when present (log,
bower.json
etc.)I suspect the problem is in brunch because I checked the transpiled
public/vendor.js
file, I can see the module'react/lib/ReactAddonsDOMDependencies.js'
is registered but I am not seeing the module'react-dom/lib/ReactPerf'
registered,we can see the file content here:
require('react-dom/lib/ReactPerf')
is conditionally loaded when not in production mode, which is needed during development, so question here is does brunch support this kind of conditionally loading a module? if so, what changes in brunch-config is required?https://unpkg.com/[email protected]/lib/ReactAddonsDOMDependencies.js
Beta Was this translation helpful? Give feedback.
All reactions