可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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.
回答1:
You can resolve this problem by adding nodemon to you package.json
npm install nodemon --save
The problem happens when nodemon does not exist in /node_modules/.bin
回答2:
Try to check installed global packages npm list -g --depth=0
. If you will not find nodemon
, - install it with flag -g
or --save-dev
. Don't install nodemon
with flag --save
, because nodemon
uses only for development
.
回答3:
under your current project directory, run
npm install nodemon --save //save in package.json so that the following code cam find your nodemon
then under "scripts" in your package.json file, add "start": "nodemon app.js" (or whatever your entry point is)
so it looks like this:
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
}
and then run
npm start
That avoids complicate PATH settings and it works on my mac
hope can help you ;)
回答4:
Install nodemon
globally using following command. It works on my computer, and I'm sure it will work on your system also.
npm install nodemon -g --save
Sometimes you should have the permission to install it globally. It can be easily done by using following command.
In LINUX UBUNTU:
sudo npm install nodemon -g --save
In Fedora:
a) su
b)npm install nodemon -g --save
回答5:
Here's how I fixed it :
When I installed nodemon using : npm install nodemon -g --save
, my path for the global npm packages was not present in the PATH variable .
If you just add it to the $PATH variable it will get fixed.
Edit the ~/.bashrc
file in your home folder and add this line :-
export PATH=$PATH:~/npm
Here "npm" is the path to my global npm packages . Replace it with the global path in your system
回答6:
You have to simply installed it globally.
npm install -g nodemon
回答7:
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.
回答8:
I had this problem and even after I have used the command npm install nodemon --save
in my application, I still had problem with nodemon.
I just resolved after I installed nodemon globally, using the command:npm install nodemon -g
回答9:
Had the same problem otherwise was just working fine a day ago.
Very simple fix
first check if nodemon exists on your system globally or not
To check
npm list -g --depth=0
If you don't see then install
it npm install -g nodemon
(g stands for globally)
If you see it still doesn't work then you need to configure environment variable
I use Windows OS. On Windows navigate to
Control panel>System>Advanced System Settings>Environment Variables>double-click on PATH
Now check if you have this PATH C:\Users\yourUsername\AppData\Roaming\npm
If not, you will see some existing paths, just append to it separating with semicolon. That's it! Worked for me.
For me node was installed in C:..\Roaming\npm and for you if the PATH is different, you will put in whatever applcable.
回答10:
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.
回答11:
You can always reinstall Node.js. When I had this problem, I couldn't fix it, but all I did was update the current version of Node. You can update it with this link: https://nodejs.org/en/download/
回答12:
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 -
- 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...
- I ran
npm uninstall -g nodemon
- 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).
- 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
- 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)
- 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!
回答13:
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.
回答14:
Try to install nodemon globally.
sudo npm install -g nodemon
回答15:
--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!
回答16:
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!