I have a problem: nodemon does not run off the npm script (e.g. npm start
),
but if nodemon is called on the command line outside the npm script, nodemon run
I got this issue while deploying on Heroku. The problem is on Heroku the don't include the devDependencies on its own. To fix this issue, simply run the command in the terminal:
heroku config:set NPM_CONFIG_PRODUCTION=false
Make sure to include nodemon in your devDependencies
"devDependencies": {
"nodemon": "^2.0.6"
}
I would suggest uninstalling nodemon and then reinstalling it
https://www.npmjs.com/package/nodemon
Or try changing the script
"scripts": {
"start": "nodemon fileName.js",
"start:dev": "nodemon fileName.js"
}
Hope it would help :)
I wanted to add how I fixed this issue, as I had to do a bit of mix and match from a few different solutions. For reference this is for a Windows 10 PC, nodemon had worked perfectly for months and then suddenly the command was not found unless run locally with npx. Here were my steps -
npm list -g
--depth=0
, in my case it was installed, so to start fresh... npm uninstall -g nodemon
npm install -g --force nodemon --save-dev
(it might be recommended to try running npm install -g nodemon --save-dev
first, go through the rest of the steps, and if it doesn't work go through steps 2 & 3 again using --force).npm config get prefix
, which in my case was located at C:\Users\username\AppData\Roaming\npmexport PATH=%PATH%;C:\Users\username\AppData\Roaming\npm;
(Obviously replace "username" with whatever your username is, or whatever the file path was that was retrieved in step 4)I hope this helps anyone who has been struggling with this issue for as long as I have!
--save, -g and changing package.json scripts did not work for me. Here's what did: running npm start
(or using npx nodemon
) within the command line. I use visual studio code terminal.
When it is successful you will see this message:
[nodemon] 1.18.9
[nodemon] to restart at any time, enter rs
[nodemon] watching: .
[nodemon] starting node app.js
Good luck!
This solution had worked for me:
I assume that you have installed nodemon globally. If it's done follow this steps:
open your .bash_profile file:
nano .bash_profile
past this to add a new alias in your bash profile:
alias nodemon='~/.npm-global/lib/node_modules/nodemon/bin/nodemon.js'
Now you can use nodemon command anywhere.
I found a very easy solution. Simply delete the npm and npm cache folder from your pc. Reinstall it again, but the mistake that many of us make is not installing npm globally.So:
npm i -g npm
And then, install nodemon globally:
npm i -g nodemon
Now,nodemon works globally, even without using the command:
npx nodemon <yourfilename>.js