-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
babel-plugin-transform-remove-console doesn't work with RN #10412
Comments
I do have the same problem when bundling an iOS app. |
I do have the same on RN ^0.31.0. |
I bet this is related to 3137ba9 (submitted by @javache , reviewed by @davidaurelio ) because that has some odd "declare var console: typeof console &" stuff going on in it. IMO if we're going to support this transform we need some sort of test that ensures it actually works - otherwise I don't see how to avoid breaking the functionality in the future. Actually since the code works this might be a bug with the babel transform itself. Could you try just running this babel transform on the ExceptionsManager file independently and see what's going wrong? |
Is there a alternative solution to removing console statements for now ? |
@note89 As a workaround I would just write a log function that only writes to console.log when it's in development mode and use the custom log function. |
Tnx ! i did this.
|
I have the same problem, any progress on this at all? |
I'd like to note that it worked the expected way on both:
By the moment I am using @note89 solution, but I guess it is not the ideal. Also to try with different |
I have the same problem too. |
+1 |
It didn't throw any error for Android when i run |
For those using Check your iOS/Android log for the tag |
The original plugin code is probably too broad in detecting what nodes to remove.
|
thank you for sharing that code @mp31415 thank you in advance. |
I never developed any babel transform plugins, so I'm not sure what "raw code" is. I just modified index.js file in the already installed node module (hoping that at some point the issue will be fixed and my changes will be overwritten with the update). So the code above is all that I have. This code lets me to assemble JS code without any console.log statements (without breaking RN build). |
+1 |
1 similar comment
+1 |
Does anyone know if this works with RN Version 0.38.0+? |
OK so in conclusion this plugin either does not work on React Native or at least there is no real guarantee that this plugin will continue to work. I think the best thing to do here is to just remove the advice that people use this plugin - it's sort of out of scope for React Native itself. I have a PR up to fix the docs at #12315 so I am going to close this issue. Thanks everyone for pointing this problem out and offering workarounds! |
Summary: Our docs suggest using this babel plugin to remove console.log statements in production. Unfortunately, it does not actually work when you run it on a new React Native project, and the root cause is that the plugin does not handle all cases correctly. See discussion in #10412 . For now, we should just stop recommending that people use this plugin, because it doesn't work. Closes #12315 Differential Revision: D4538567 Pulled By: hramos fbshipit-source-id: f3ae1b9143130a05601907ee902a02fc0b2818b0
Just let everyone know it has been fixed by babel/minify#421, the main problem is ExceptionsManager.js#L103-L104, we can waiting for new release of |
@jhen0409 Thanks I hope this functionality gets brought into RN, they really should considering this as an optimization step for final binary generation. |
Summary: Our docs suggest using this babel plugin to remove console.log statements in production. Unfortunately, it does not actually work when you run it on a new React Native project, and the root cause is that the plugin does not handle all cases correctly. See discussion in facebook#10412 . For now, we should just stop recommending that people use this plugin, because it doesn't work. Closes facebook#12315 Differential Revision: D4538567 Pulled By: hramos fbshipit-source-id: f3ae1b9143130a05601907ee902a02fc0b2818b0
Summary: Our docs suggest using this babel plugin to remove console.log statements in production. Unfortunately, it does not actually work when you run it on a new React Native project, and the root cause is that the plugin does not handle all cases correctly. See discussion in facebook#10412 . For now, we should just stop recommending that people use this plugin, because it doesn't work. Closes facebook#12315 Differential Revision: D4538567 Pulled By: hramos fbshipit-source-id: f3ae1b9143130a05601907ee902a02fc0b2818b0
Summary: Our docs suggest using this babel plugin to remove console.log statements in production. Unfortunately, it does not actually work when you run it on a new React Native project, and the root cause is that the plugin does not handle all cases correctly. See discussion in facebook#10412 . For now, we should just stop recommending that people use this plugin, because it doesn't work. Closes facebook#12315 Differential Revision: D4538567 Pulled By: hramos fbshipit-source-id: f3ae1b9143130a05601907ee902a02fc0b2818b0
@jhen0409 - are you sure it's been fixed? The latest version of |
Before I do that, just to make sure I'm testing this correctly: react-native bundle --entry-file app.react.js --platform ios --dev false --bundle-output dist/ios.prod.js The resultant file at The relevant parts of my {
"dependencies": {
...
"react-native": "^0.43.3",
...
},
"devDependencies": {
...
"babel-plugin-transform-remove-console": "^6.8.1",
"babel-preset-react-native": "1.9.1",
...
},
} Is anybody else experiencing this issue? Am I running |
@Ashoat Did you also add the |
@danez: Sorry for forgetting to include {
presets: ['react-native'],
plugins: ['transform-remove-console'],
} I'm using |
Summary: This PR adds a suggestion to the docs to use the `transform-remove-console` babel plugin in production to remove `console.*` calls. This information was previously in the docs, but was [removed](e759573) because the babel plugin [didn't work](#10412). But now it's working well, as reported [here](#10412 (comment)), so it would be helpful to add the suggestion again. Ideally, this would be done automatically, as I suggested in #8337 Closes #13651 Differential Revision: D4954872 Pulled By: hramos fbshipit-source-id: 89ae1b813c50e678f0826f16ef88c8604e13d889
Summary: This PR adds a suggestion to the docs to use the `transform-remove-console` babel plugin in production to remove `console.*` calls. This information was previously in the docs, but was [removed](facebook@e759573) because the babel plugin [didn't work](facebook#10412). But now it's working well, as reported [here](facebook#10412 (comment)), so it would be helpful to add the suggestion again. Ideally, this would be done automatically, as I suggested in facebook#8337 Closes facebook#13651 Differential Revision: D4954872 Pulled By: hramos fbshipit-source-id: 89ae1b813c50e678f0826f16ef88c8604e13d889
@Ashoat
but it seems to me that it will remove the log even on development mode. How to do it, only on release? Documentation suggest something like this, but it did work. { I'm also running straight from the react-native packager.
|
Do you got an "unexpected keyword import" error? Try this:
|
@ricardosasilva after building the app for production with above settings, its crashing when there is a warning. [Like defined proptype is different than the actual etc.] trace log:
|
Issue Description
I tried using
babel-plugin-transform-remove-console
as specified in the performance docs in my RN project (v0.34.1) and also in a newly initialized AwesomeProject (v0.35.0), but it looks like the RN packager (or JavaScriptCore?) doesn't like the transformed code. Both throw the same error when running assembleRelease with gradle:I also tested it on another project for the web, which is bundled with webpack and works as expected, so I didn't open an issue at the babel repo yet because it might be RN related.
Note: In #8337, there was effort to integrate this functionality directly into RN, but adding the transform plugin guide into the docs was chosen instead.
Steps to Reproduce / Code Snippets
.babelrc
according to the perf docsconsole.log('blah')
somewhere into one of the root index filesExpected Results
Transformed code without
console.*
calls.Additional Information
The text was updated successfully, but these errors were encountered: