nodemon not found in npm

前端 未结 29 1188
终归单人心
终归单人心 2020-12-24 10:17

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

相关标签:
29条回答
  • 2020-12-24 11:01

    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"
      }
    

    Incase your error is not in Heroku

    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 :)

    0 讨论(0)
  • 2020-12-24 11:03

    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 -

    1. Check to see if it is installed globally by running npm list -g --depth=0, in my case it was installed, so to start fresh...
    2. I ran npm uninstall -g nodemon
    3. Next, I reinstalled using 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).
    4. Then I checked where my npm folder was located with the command npm config get prefix, which in my case was located at C:\Users\username\AppData\Roaming\npm
    5. I modified my PATH variable to add both that file path and a second entry with \bin appended to it (I am not sure which one is actually needed as some people have needed just the root npm folder and others have needed bin, it was easy enough to simply add both)
    6. Finally, I followed similar directions to what Natesh recommended on this entry, however, with Windows, the .bashrc file doesn't automatically exist, so you need to create one in your ~ directory. I also needed to slightly alter how the export was written to be export 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!

    0 讨论(0)
  • 2020-12-24 11:05

    --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!

    0 讨论(0)
  • 2020-12-24 11:06

    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.

    0 讨论(0)
  • 2020-12-24 11:06

    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
    
    0 讨论(0)
提交回复
热议问题