nodemon not found in npm

2019-02-02 22:32发布

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 runs as normal.

$ nodemon server.js
14 Feb 22:59:51 - [nodemon] v1.3.7
14 Feb 22:59:51 - [nodemon] to restart at any time, enter `rs`
14 Feb 22:59:51 - [nodemon] watching: *.*
14 Feb 22:59:51 - [nodemon] starting `node server.js`

How it is called in npm script:

package.json

{
...
  "scripts": {
    "start": "nodemon server.js"
  }
}

When npm start script is run:

$ npm start
> aaa@0.0.1 start /home/akul/Documents/aaa
> nodemon server.js

sh: 1: nodemon: not found

npm ERR! Linux 3.13.0-45-generic
npm ERR! argv "node" "/home/akul/npm-global/bin/npm" "start"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.0
npm ERR! code ELIFECYCLE
npm ERR! aaa@0.0.1 start: `nodemon server.js`
npm ERR! Exit status 127
npm ERR! 
npm ERR! Failed at the aaa@0.0.1 start script 'nodemon server.js'.
npm ERR! This is most likely a problem with the aaa package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     nodemon server.js
npm ERR! You can get their info via:
npm ERR!     npm owner ls aaa
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/akul/Documents/aaa/npm-debug.log

I've been looking for a solution, but have not found one.

16条回答
The star\"
2楼-- · 2019-02-02 23:03

NPM is used to manage packages and download them. However, NPX must be used as the tool to execute Node Packages

Try using NPX nodemon ...

Hope this helps!

查看更多
\"骚年 ilove
3楼-- · 2019-02-02 23:04

heroku runs in a production environment by default so it does not install the dev dependencies.

if you don't want to reinstall nodemon as a dependency which I think shouldn't because it's right place is in devDependencies not in dependencies.

instead, you can create a two npm script to avoid this error by running nodemon only in your localhost like that:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node app.js",
    "start:dev": "nodemon --watch"
},

and when you want to run the project locally just run in your terminal npm run start:dev and it will load app.js by nodemon.

while in heroku npm start runs by default and load app.js from a normal node command and you get rid of that error.

查看更多
啃猪蹄的小仙女
4楼-- · 2019-02-02 23:05

First install nodemon to your working folder by

npm install nodemon

Add the path of nodemon to the path variable of Environment Variable of System environment. In my case the path of nodemon was.

C:\Users\Dell\Desktop\Internship Project\schema\node_modules\.bin

It worked for me.

查看更多
萌系小妹纸
5楼-- · 2019-02-02 23:08

You have to simply installed it globally. npm install -g nodemon

查看更多
相关推荐>>
6楼-- · 2019-02-02 23:08

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

查看更多
一纸荒年 Trace。
7楼-- · 2019-02-02 23:12

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.

查看更多
登录 后发表回答