-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Info: Fails to build a minified create-react-app with ipfs #1321
Comments
@eugenioclrc thanks for the heads up, I believe we used I am going to award the bounty to @fsdiogo anyway for dealing with webpack bundling the proper way. @fsdiogo, can you please go to https://gitcoin.co/issue/ipld/js-cid/38/121 and claim the bounty? Also thanks @AquiGorka and @dimkk for putting effort into solving the build issue. I wish I had more funds to split for everyone involved, and I think we all agree that @fsdiogo did a good job here. |
Hey @abitrolly, I fixed the uglify issue in But, the bundling of I'll gladly collect the bounty, but only if I solved your problem 🙂 |
Just to set expectations, we're in no rush to get The best way to deal with this is to compile your package if you wish for people to use it in the browser. |
Thanks for the input @Timer. Yes, we're already discussing a way to offer a compiled version of js-ipfs, we'll see how that goes! |
Until the 0.29 release lands, you do still need to provide config to the UglifyJsPlugin (which now uses uglify-es) to get it to compress IPFS without breaking things. Here is what we're using in peer-pad webpack config now: new UglifyJsPlugin({
// see: https://github.com/webpack-contrib/uglifyjs-webpack-plugin#options
cache: true,
parallel: true,
// see: https://github.com/mishoo/UglifyJS2/tree/harmony#minify-options
uglifyOptions: {
compress: {
// Needed to minify js-ipfs, see: https://github.com/ipfs/aegir/pull/214
unused: false,
// Needed to minify js-ipfs until v0.29 see: https://github.com/ipfs/js-ipfs/issues/1321
keep_classnames: true,
// Disabled because of an issue with Uglify breaking seemingly valid code:
// https://github.com/facebookincubator/create-react-app/issues/2376
// Pending further investigation:
// https://github.com/mishoo/UglifyJS2/issues/2011
comparisons: false,
// don't display warnings when dropping unreachable code
warnings: false,
},
mangle: {
// Needed to minify js-ipfs until v0.29 see: https://github.com/ipfs/js-ipfs/issues/1321
keep_classnames: true,
safari10: true,
},
output: {
comments: false,
// Turned on because emoji and regex is not minified properly using default
// https://github.com/facebookincubator/create-react-app/issues/2488
ascii_only: true,
},
sourceMap: shouldUseSourceMap,
}
}), that's a merge of the ejected |
Many thanks for the input @olizilla. I'll update the first post to clear that up 👍 |
As a workaround, I am currently using My module.exports = function override(config, env) {
if (env === 'production') {
// Remove UglifyJsPlugin
config.plugins.splice(3, 1);
}
return config;
}; You can of course replace the item at index 3 in IMO it's cleaner than this trick proposed in the 1st post. |
I tried to create a new app with create-react-app and then adding IPFS v.0.29, that just came out. It starts if installed with node < 10, but still won't build because of |
@hugomrdias I just tested out your fix on a new project, and it works great! Let's get it merged and add some info about it here. |
@louismerlin fixes for node@10 are about to land #1358 |
🔥🔥🔥 cool !! Temporary instructions to use IPFS on a CRA $ # Create a new application
$ npx create-react-app@next --scripts-version=2.0.0-next.66cc7a90
$ # Upgrade an existing application
$ yarn upgrade react-scripts@2.0.0-next.66cc7a90 add this to package.json "resolutions": {
"libp2p-switch": "libp2p/js-libp2p-switch#feat/swap-quick-lru"
} re-install deps using yarn i don't think npm supports rm node_modules
yarn References: |
I highly suggest to not do this, you are disabling minification and dead-code elimination which will result in a very slow React application in production and potential for secrets to be leaked. #1321 (comment) is the proper approach. |
Apologies if this is a n00b question. I followed #1321 (comment) My CRA had already been created, so i didn't do the first step (npx create-react-app@next --scripts-version=2.0.0-next.66cc7a90), just started at the next step installing yarn and running the update command. I'm still getting the same error. Am I missing something obvious? |
@blake41 did you run yarn instead of npm? and also have you done a clean re-install ? |
@hugomrdias i did use yarn, but was able to figure out a solution, thanks for responding! |
Thanks @hugomrdias, this worked for me. Although I didn't need the "resolutions" part. |
Closing this now that a solution has been found. Tracking adding working examples for various bundlers in #1436 |
There are a lot of issues regarding
create-react-app
andjs-ipfs
, let's keep that discussion in this one, as well as options to make them play well together.✅ js-ipfs minified version
The minified version of IPFS (when you run
npm run build
and outputs todist/index.min.js
) wasn't being uglified (compressed and mangled) due to the way we were doing some type checks. This has been solved and will be available in the 0.29.0 release.ℹ️ create-react-app
For those who are using
create-react-app
with IPFS, you'll still encounter some issues when trying to build a production version. The problem comes fromcreate-react-app
itself and not IPFS, because it uses UglifyJS that still doesn't support ES6. As IPFS doesn't offer a transpiled version, trying to build a production version of a CRA with IPFS will fail to minify. A new version of CRA is being worked on, usinguglify-es
that supports ES6. Until then, developers have a few options:uglify-es
intead ofuglify-js
The text was updated successfully, but these errors were encountered: