nodemon "restarting due to changes..." repeatedly displays in VSCode and slows down every restarting process - visual-studio-code

I use nodemon version 1.18.9 (Latest version as of today).
I use Visual Studio Code (VSCode). I open a terminal and execute nodemon dev-server.js but it displays this repeatedly
restarting due to changes...
as follows
and after a few seconds it will complete its restarting process.
I use Windows 10.
Any suggestions?

package.json
{
"scripts": {
"nodemon": "nodemon dev-server.js"
},
}
start nodemon by npm
$ npm run nodemon
save dev-server.js file, nodemon will restart twice
start nodemon direct
$ nodemon dev-server.js
save dev-server.js file, nodemon is all right
osx 10.11.3
nodemon 1.9.2
=============UPDATED ANSWER FROM COMMENTS======================
updating answer from comments as logic from comments worked for this problem.
try adding delay for some time. let me know if it works.
nodemon lib/dev-server.js --delay 1 ..
whatever your directory is.

I guess you have to change the settings on the VSCode, go to File->Auto Save(unmark the option). After that the project will restart only when you use ctrl+s on the specific path.
Edit: I did some tests on my computer and I reproduced what you trying to mean, probably you are trying to use diferent extensions that nodemon does not support.
Take a look on this part of the documentation:
Specifying extension watch list By default, nodemon looks for files
with the .js, .mjs, .coffee, .litcoffee, and .json extensions. If you
use the --exec option and monitor app.py nodemon will monitor files
with the extension of .py. However, you can specify your own list with
the -e (or --ext) switch like so:
nodemon -e js,jade Now nodemon will restart on any changes to files in
the directory (or subdirectories) with the extensions .js, .jade.
try to run nodemon -e ts,json(all extensions that you want to be listener) dev-server.js. When I removed the extension I got the same issue of you.

please set Windows Environment Path
Right Click PC/My Computer
Properties
Environment
Path --> Edit --> New
Paste:- C:\Windows\System32
ok
then restart VSCode

Try to build your application without using nodemon
Correct the errors, which may be the result of tslint being unable to fix something and generating a syntax error
Restart your application with nodemon

Related

VSCode complains that resolving my environment takes too long

When I launch VSCode from the dock, it always complains that
Resolving your shell environment is taking very long. Please
review your shell configuration.
and then a bit later
Unable to resolve your shell environment in a reasonable time.
Please review your shell configuration.
According to this page, Resolving Shell Environment is Slow, the first message is displayed if .bashrc takes more than three seconds and the second is displayed if it takes longer than ten seconds.
I opened a terminal in VSCode and sourced my .bashrc file
dpatterson#dpconsulting$ time source ~/.bashrc
real 0m1.448s
user 0m0.524s
sys 0m0.671s
dpatterson#dpconsulting$
As you can see, it takes less than 1.5 seconds.
Environment:
MacOS Mojave 10.14.6
VSCode 1.53.0
Hopefully someone knows what is causing this.
Barring that, maybe someone can point me to the code that actually generates these errors.
TIA
encountered the same situation and find the issue:
https://github.com/microsoft/vscode/issues/113869#issuecomment-780072904
I extract nvm load code to the condition function ref in the issue, solved this problem:
function load-nvm {
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
[[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
}
# nvm
if [[ "x${TERM_PROGRAM}" = "xvscode" ]]; then
echo 'in vscode, nvm not work; use `load-nvm`';
else
load-nvm
fi
Open VS Code from a terminal:
code .
Restarting VSCode on BigSur works for me.
You can also check your user settings to make sure it matches the path of the shell that your terminal uses.
Check https://code.visualstudio.com/docs/supporting/troubleshoot-terminal-launch for other troubleshooting steps.
OSX Work-around
Background
If VS Code is started via an OSX (or Linux) GUI interface and there's a shell rc process that takes more than 10 seconds to complete during start-up (e.g. nvm) VS Code simply stops trying to start-up that shell.
Work-around
The two known solutions are to either get rid of the process that takes more than 10 seconds or start VS Code from the command line (i.e. code .).
This work-around is for those of us on OSX who —for whatever reason— explicitly don't/can't get rid of the 10+ second process and who —again, for whatever reason— start VS Code via the GUI.
While the following is less desirable than VS Code just having a configuration that we can change, it's still better than having to remember to run code . from the terminal, and it's much, much better than not using nvm (or switching to an alternative).
Note: The file extension does need to be changed between .command and .app several times — this is not a mistake! ;)
Create a new file with the following:
#!/bin/sh
code .
Save the file with a .command extension in your "Applications" directory, e.g. ~/Applications/vs-code-cli-starter.command.
In a terminal, change that new file's permissions:
chmod +x fileName.command
From Finder, right click-on your new app/command and select "Get Info", then repeat with your actual VS Code application.
Drag the big icon from the "Preview" section of the actual VS Code's "Get Info" to the small icon in the upper-left of your newly created app/command's "Get Info".
Close the two "Get Info" panels.
In the "Applications" directory, update the file extension from .command to .app, e.g. vs-code-cli-starter.app.
Drag the newly created app's icon to your dock.
In the "Applications" directory, swap the file extension back from .app to .command, e.g. vs-code-cli-starter.command.
Enjoy
For Linux:
if [[ "$VSCODE_PID" = "" ]]; then
echo "slow or blocking operations"
fi
Thanks to Hemisu's answer.
For those who uses zsh, .ohmyzsh and powerlevel10k prompt:
Get all your exports EXCEPT export ZSH= and nvm stuff and put them in the bottom of .zshrc file.
Insert this line at the top: if [[ "$VSCODE_PID" = "" ]]; then
Before your exports at the bottom, insert an fi (end if)
Now, all your ohmyzsh, nvm and ohmyzsh themes are not loaded when VSCode initializes (the built in terminal still works fine, with ohmyzsh).
In my case, outside that if/fi there is only exports for PATH, LDFLAGS and CPPFLAGS.
Thanks to M Imam Pratama answer.
In Linux, you can open "alacarte" and make a new shortcut with the command "code" and click the box "Open in a terminal".
Go to project location and open with code . in terminal (if you are in linux) or cmd (if you are in windows.) That should resolve this issue.
When directly opened from vscode app it happens, even I have faced this.
it's a very common error or we can say complain by vs code
so here is the solution - do not open vs code directly from its icon or directly from application instead you can do is just open vs code from terminal/cmd obviously for linux/windows respectively by typing this command -> $ code .
if this command is not working then reinstall the vs code and check all the boxes before installing it will also allows you to open vs code from folder directly by clicking right side of mouse and just click open this folder with other application and select vs code.

Flutter and Dart -> add path on Ubuntu 20.04

I am trying to add flutter to the path but no solution is working for me right now. It was working before when I installed it from snap. Now I am cloning flutter repo into the opt folder and No matter what I try, flutter is not working. I am using ZSH terminal.
So far I have tried:
Adding export PATH=~/opt/flutter/bin:$PATH on last line of .zshrc and .bashrc file.
Running export PATH="$PATH:~/opt/flutter/bin" on the terminal.
And bunch of other tweaks on the keywords but none of the things seems to work.
Try this if you mean you have cloned flutter to /opt folder
export PATH="$PATH:/opt/flutter/bin"
Also if you doesn't mean that and you solely mean ~/opt folder then first verify your flutter installation by typing
~/opt/flutter/bin/flutter
in your terminal,
It should launch flutter it your terminal if not then either your installation is broken or you have to type
chmod +x -R ~/opt/flutter/bin
to make flutter executable if it's not.
PS: Also don't forget to restart your shell if you haven't cause you have to restart you shell after changing something in your .rc files.
I hope I have helped you if not please comment so that I can improve the answer.
This work on Ubuntu.
Add to file .profile the following line:
export PATH="$PATH:/home/your_user_name/opt/flutter/bin

Bazel tab auto complete in zsh not working

I use oh-my-zsh and I have a bazel project. I want tab complete. So that I can do bazel build //src/<tab> and get auto complete.
The first thing I tried was following:
https://docs.bazel.build/versions/master/completion.html. I included the _bazel file under a directory on my $fpath. Then I restarted my terminal and got no tab complete.
Next I tried using an oh-my-zsh plugin. https://github.com/jackwish/bazel. I cloned the plugin into the correct location, added bazel to my zshrc plugins and did source ~/.zshrc
Still no tab completion.
I installed bazel using brew. I have tried brew uninstall bazel and reinstalling it. No luck...
$ echo $fpath
... /Users/<username>/.oh-my-zsh/completions ...
$ ls /Users/<username>/.oh-my-zsh/completions
_bazel
I want to press tab and get a list of options and be able to tab through them.
You need to re-initialize the completion. The completion system in ZSH collects completion file in fpath and record them in a .zcompdump file as an index for existing completions. After a new completion file is added, you need to redo the process.
Solution
Put the following content into your .zshrc.
# add the _bazel into path
fpath+=(/path/to/_bazel)
Re-collect completions and generate .zcompdump. Run the following command in a new interactive ZSH shell.
rm -f ~/.zcompdump; compinit
I remember oh-my-zsh doesn't do the compinit for you. You may need to add the compinit into your .zshrc.
Check the optimization here to run compinit once a day.
Extended Reading
Command completion from archlinux wiki
I had to install zsh-completions (via brew) and follow the instructions after the install to get completions to work for me.

nvm, node etc. paths missing from integrated terminal

I am using the insiders edition and zsh with ohmyzsh inside iTerm2 on OSX High Sierra.
If I launch the integrated command line in VSCode echo $path returns:
/Users/username/.yarn/bin:/Users/username/.cargo/bin:/usr/bin:/usr/bin/lldb:
/Users/username/bin:/usr/local/bin:/Users/username/.scripts:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
Obviously, the node path, nvm path etc. are missing so the terminal is not much use to me.
But typing echo $path in my terminal outside of VSCode returns:
/Users/username/.nvm/versions/node/v9.0.0/bin /Users/username/.yarn/bin
/Users/username/.cargo/bin /usr/bin /usr/bin/lldb /Users/username/bin
/usr/local/bin /Users/username/.scripts /usr/local/bin /usr/bin /bin /usr/sbin
/sbin /opt/X11/bin
Which has all the paths I need for my development activities.
I have this alias in my ~/.zshrc:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCodeInsiders" --args $* ;}
If I launch code using the alias from an external terminal the node paths are correct.
As far as I can see this is because loading code from the Dock shortcut doesn't load the terminal using my user profile so it loads the profile from /etc/zprofile instead, which sets the path using /usr/libexec/path_helper so it misses all of my important paths that I need for development.
I suspect that most people would prefer the settings from their user profiles to be used. This would mean all of our dev apps would work from the integrated terminal and also the end of the infamous nvm is not compatible with the npm config "prefix" option error caused by the improper setting of paths.
How can I get VSCode to use the environment of the terminal in my user profile when launched from the Dock?
Go to settings and edit integrated terminal
// Object with environment variables that will be added to the VS Code process to be used by the terminal on OS X
"terminal.integrated.env.osx": {},
there you can pass in your variables
The vscode docs also offer a solution for the warning nvm is not compatible with the npm config "prefix" option: currently set to "/usr/local":
https://github.com/Microsoft/vscode-docs/blob/master/docs/editor/integrated-terminal.md#why-is-nvm-complaining-about-a-prefix-option-when-the-integrated-terminal-is-launched
From the docs:
This is mostly a macOS problem and does not happen in external
terminals. The typical reasons for this are the following:
npm was globally installed using another instance of node which is
somewhere in your path (such as /usr/local/bin/npm). In order to get
the development tools on the $PATH, VS Code will launch a bash login
shell on start up. This means that your ~/.bash_profile has already
run and when an Integrated Terminal launches, it will run another
login shell, reordering the $PATH potentially in unexpected ways. To
resolve this issue, you need to track down where the old npm is
installed and remove both it and its out of date node_modules. You can
do this by finding the nvm initialization script and running which npm
before it runs, which should print the path when you launch a new
terminal.
Once you have the path to npm, you can find the old node_modules by
resolving the symlink by running a command something like this:
ls -la /usr/local/bin | grep npm
This will give you the resolved path at the end:
... npm -> ../lib/node_modules/npm/bin/npm-cli.js
From there, removing the files and relaunching VS Code should fix the issue:
rm -R /usr/local/bin/npm /usr/local/lib/node_modules/npm/bin/npm-cli.js

I can't run nodemon from Integrated Terminal of Visual Studio Code Mac OS

I have installed nodemon by: sudo npm install -g nodemon. With MacOS Terminal, i can run nodemon command.
But in Integrated Terminal of Visual Studio Code, I can't run nodemon and I don't know why.
Maybe two terminals don't sync ?
Help me, please.
In my case
changed the default shell from Powershell to CMD
restart VSCode.
VSCode now started with cmd chosen as the default, and the problem didn't happen with cmd.
Shutdown VS Code and launch it again from the command line with 'code .'.
Above approach should fix the issue. Sometime when we install node after installing visual studio some sort of environment variable path issue happens.
Looks like this has been asked by others. But here is a possible solution. In you package.json edit scripts:
"scripts": {
"serve": "nodemon server.js"
},
then npm run serve
You can also check you bash profile
if nodemon is not being found by bash.
~/.bash_profile
add
PATH=$PATH:/usr/local/bin/bin/
Check this solution
and this discussion here
I was also facing a similar problem for a long time during my web development. If you are also facing these problem in VS code, so I recommend you to install Powershell Extention in your vs code or update your Powershell Extention. And restart your vs code.