-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
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
Allow disabling of console clearing #2495
Comments
a detection of env variable (maybe |
@viankakrisna yes, that's a good idea as well! |
I'm not sure this is going to be something we allow; why not edit the file in And you really shouldn't be using console debugging anyway 😅. Why not use something like VSCode with built-in debug support? |
@Timer is there any more alternative? I've been doing console.log debugging in node since forever and don't want to switch editor :D |
You can boot up with |
@Timer thanks! That's new to me. So that's how people inspect a nested objects in node huh? I thought everyone uses their terminal for debugging node code.... However, I've tried it in CRA repo but the instruction is quickly cleared for --inspect
using I will happily add PR for contributing.md (or the root package.json) for this if we can also improve Contributor's Experience (CX?) :) |
I think this is worth considering, as the current console experience seems very strange to me. Clearing the console is kind of nice aesthetically (though not that important, in my opinion), but currently all output history in the console session is removed after running |
The |
or run it with |
Please can we add |
@viankakrisna and on Windows? |
@johnunclesam not sure 😅 does the command works under git bash? i agree it's nicer to have env variable to achieve this functionality though |
This workaround from @viankakrisna breaks the ability to interact with the server from the console. For example, it removes the ability to detect if something is already running on the default port and suggest an available port. An environment variable to disable console clearing still has merit. |
I see no benefits to clearing console, and even consider this as harmful behavior. This should not stay the default, so no flag won't fix the issue. Any deletion of user data should be intended not a side effect like here. |
Not to dogpile here, but since some of the recommendations for customizing the build of a create-react-app without ejecting involve running separate build processes, it would be really handy if this thing didn't clear the terminal. For example, I'm currently running Sass and CRA together in the same shell with |
^ this. cra blasts everything else This hack does work. |
Yes, |
This is a painful one for me too. If we want to favour interactivity over configuration as per the core ideas in the contributing guidelines, how about we add a prompt to clear the console instead of automatically clearing it? This obviously is weird, because a prompt to clear the terminal is practically useless with how easily it is manually, but it fits the requirements without deleting the debug data if the maintainers aren't willing to compromise on this one with a flag. I find the tradeoff being made here currently leans towards aesthetics over usefulness, and in this case is obviously disempowering over helpful for a good number of people. |
this should be allowed. e.g. I was trying to figure out why proxy configuration wasn't being used ( which was a bug on my CRA version) and the console clearing making it hard for me to see what is going on. A simple flag/env can be passed for this |
@viankakrisna - How can I do this from a Node process spawn? Here's what I'm working with... const reactProcess = spawn('npx', ['react-scripts', 'start']) |
This works... // scripts/launch-app.js
const {spawn} = require('child_process');
const reactProcess = spawn('npx', ['react-scripts', 'start'], {
env: Object.assign(process.env, {FORCE_COLOR: true})
detatched: true
});
reactProcess.unref();
const removeCliClearCodes = text => {
return text.replace(/\\033\[2J/g, '');
}
reactProcess.stdout.on('data', data => {
const text = String(data);
const output = removeCliClearCodes(text);
console.log(text);
}); // package.json
{
"scripts": {
"start": "scripts/launch-app"
}
} |
@alistair-hmh Thanks for posting that workaround! I noticed that in my use case, the 3rd In the end, I actually wound up taking a different approach where I replaced the const {
choosePort,
createCompiler,
prepareProxy,
prepareUrls,
} = require('react-dev-utils/WebpackDevServerUtils'); with: // Replace react-dev-utils/clearConsole with a noop in WebpackDevServerUtils
// to prevent it from clearing the console on every compile
const noop = () => {};
const webpackDevServerUtilsPath = require.resolve('react-dev-utils/WebpackDevServerUtils');
const resolveModule = (name) =>
name.charAt(0) !== '.' ? name : path.resolve(path.dirname(webpackDevServerUtilsPath), name);
const consolePreserveExports = {};
const consolePreserveContext = {
require: (name) => (name.endsWith('clearConsole') ? noop : require(resolveModule(name))),
console,
exports: consolePreserveExports,
module: {
exports: consolePreserveExports,
},
process,
};
vm.runInNewContext(fs.readFileSync(webpackDevServerUtilsPath), consolePreserveContext);
const {
choosePort,
createCompiler,
prepareProxy,
prepareUrls,
} = consolePreserveContext.module.exports; 🤢 |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Not to be snarky, but closing via stale bot seems like a rude ending to this issue |
Ya, I'm curious to see a resolution on this. Is the decision that maintainers want to leave this as is? Would a PR be accepted? What would the ergonomics of an accepted solution look like? |
@drewswaycool Thanks I think the PR needs to add an option and not remove the default behaviour that some may rely on. I'm not familiar with CRA's code but you should add a flag or It's the first time I use a CLI tool that clears the current shell history (most actually scroll to the bottom keeping the buffer intact), maybe that could be the best of both worlds? |
Quick and dirty solution. Change this in start.js from: const WebpackDevServer = require('webpack-dev-server');
const clearConsole = require('react-dev-utils/clearConsole'); to: require('react-dev-utils/clearConsole');
const clearConsole = ()=>{}
require.cache[require.resolve('react-dev-utils/clearConsole')].exports = clearConsole
const WebpackDevServer = require('webpack-dev-server'); |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
I don't believe this issue should be stale just as #6102 is not stale. |
Update from @Timer here --> #6102 (review)
👎 |
@gaearon @Timer There are literally tons of people working on projects based on Still, there are dozens of reasons why adjust the build process might be worthwhile, so people tend to use In all of these important and comprehensible use cases, the clearing of the console by It is understandable that PR #6102 is not merged because the team has decided that they want to keep clearing the console despite the obvious drawbacks in a lot of cases such as the ones detailed above. Still, this issue persists and keeps being a problem to a lot of people. Please reconsider the introduction of an additional environment variable that allows users to prevent the console clearing from happening. This way, we can default to clearing but allow users with special use cases to prevent it in a sensible way. |
@drewswaycool @codepunkt @lmorchard @acusti @razzfox How do you feel about using concurrently as a workaround for this issue:
Or
Or
Or if you have lerna installed in a monorepo,
It will break input interactivity but it seems these two workarounds should be sufficient for most use cases? |
@bugzpodder Clearing the console is intrusive, leaving it alone is not.... why is being intrusive the default behavior here. This makes no sense. |
@bugzpodder I think the bummer here is the idea of needing a workaround at all.. It just feels like out of the box clearing the console should not be the default. Workarounds are fine.. but no workarounds are better. |
Given that this issue is about providing a workaround to optionally not clear the console and several ways were provided to do so, I think we can finally resolve this issue. I don't see the need to further continuing this debate given the opinionated nature of CRA's defaults. |
This comment has been minimized.
This comment has been minimized.
Typically, "workarounds" are things you do to avoid a bug while it's being fixed - not generally advised practice. |
When debugging an ejected script via console.logging different things, I found it quite difficult / annoying that multiple pieces of this script clear the the console when it detects
stdout.isTTY
(start.js
andreact-dev-utils/WebpackDevServerUtils.js
).I would like to recommend some kind of argument or environment variable to disable that behaviour, so that we wouldn't need to eject and modify and clone to simply enable console logging.
The text was updated successfully, but these errors were encountered: