简体   繁体   English

NPM 实时服务器:找不到命令

[英]NPM live-server: command not found

I install live-server globally with:我在全球范围内安装实时服务器:

npm install -g live-server but for some reason it is not be found and I get the following error npm install -g live-server但由于某种原因找不到它,我收到以下错误

bash: live-server: command not found after command live-server bash:live-server:在命令live-serverbash: live-server: command not found命令

Everything is correctly installed:一切都已正确安装:

/Users/username/npm-global/bin/live-server ->
/Users/username/npm-global/lib/node_modules/live-server/live-server.js
live-server@0.9.2 /Users/username/npm-global/lib/node_modules/live-server
├── object-assign@4.0.1
├── colors@1.1.2
├── event-stream@3.3.2 (pause-stream@0.0.11, duplexer@0.1.1, stream-combiner@0.0.4, from@0.1.3, map-stream@0.1.0, split@0.3.3, through@2.3.8)
├── opn@4.0.0 (pinkie-promise@2.0.0)
├── send@0.13.1 (escape-html@1.0.3, destroy@1.0.4, statuses@1.2.1, etag@1.7.0, fresh@0.3.0, range-parser@1.0.3, ms@0.7.1, debug@2.2.0, depd@1.1.0, mime@1.3.4, on-finished@2.3.0, http-errors@1.3.1)
├── morgan@1.7.0 (on-headers@1.0.1, basic-auth@1.0.3, depd@1.1.0, on-finished@2.3.0, debug@2.2.0)
├── connect@3.4.1 (utils-merge@1.0.0, parseurl@1.3.1, debug@2.2.0, finalhandler@0.4.1)
├── faye-websocket@0.10.0 (websocket-driver@0.6.4)
├── watchr@2.3.10 (bal-util@1.18.0)
└── serve-index@1.7.3 (parseurl@1.3.1, escape-html@1.0.3, batch@0.5.3, http-errors@1.3.1, debug@2.2.0, mime-types@2.1.10, accepts@1.2.13)

What am I missing here?我在这里错过了什么?

Add the path to your npm installation to your path.将您的 npm 安装路径添加到您的路径中。 Just add this line at the end of .bash_profile .只需在.bash_profile的末尾添加这一行。 Run it in bash first, to make sure it works before putting it in .bash_profile首先在 bash 中运行它,以确保在将其放入.bash_profile之前它可以工作

export PATH=$PATH:/Users/username/npm-global/bin

The main problem is that node js does not know the path of the installed modules ..主要问题是节点js不知道安装模块的路径..

Type this command to get the path of all the global modules.键入此命令以获取所有全局模块的路径。

npm bin -g

It will display the path (C:\\Users\\gf\\AppData\\Roaming\\npm) and also show (not in PATH env variable)它将显示路径 (C:\\Users\\gf\\AppData\\Roaming\\npm) 并显示(不在 PATH 环境变量中)

Copy the path and add it to the path variable of your computer (just like you do while installing other software) for eg : In Windows 7 - Right click on my computer ->select properties -> select advanced system settings -> environment variables复制路径并将其添加到您计算机的路径变量中(就像您在安装其他软件时所做的那样)例如:在 Windows 7 中 - 右键单击​​我的计算机 -> 选择属性 -> 选择高级系统设置 -> 环境变量

在此处输入图片说明

Double click on the Path variable双击路径变量

在此处输入图片说明

In the variable value first type a semicolon and paste the path which you copied and that's it every thing should work now..在变量值中,首先输入一个分号并粘贴您复制的路径,就是这样,现在一切都应该可以工作了..

Just a note, don't just blindly copy and paste the path /Users/username be sure you do the请注意,不要只是盲目地复制和粘贴路径 /Users/username 确保您执行

npm bin -g

as explained by others and get that actual path into export PATH=$PATH:/YourActualPathHERE正如其他人所解释的,并将实际路径导入export PATH=$PATH:/YourActualPathHERE

In my case (Ubuntu with npm installed from package) live-server module was not installed.在我的情况下(从包安装了 npm 的 Ubuntu)没有安装live-server模块。 It helps:它有助于:

npm install -g live-server

try to install as root/Administrator尝试以 root/管理员身份安装

sudo npm install -g live-server

Hope this will solve your problem.. its works for me...希望这能解决你的问题......它对我有用......

Update to http-server.更新到 http 服务器。 You can install globally using您可以使用全局安装

npm install --global http-server

You can find the docs at https://www.npmjs.com/package/http-server您可以在https://www.npmjs.com/package/http-server找到文档

If you on windows 10.如果您使用的是 Windows 10。

Assuming Nodejs is installed, npm is installed, GitBash terminal is installed假设安装了 Nodejs,安装了 npm,安装了 GitBash 终端

1.Install Linux subsystem for windows: Open PowerShell and type: 1.为windows安装Linux子系统:打开PowerShell并输入:

Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

  1. Open gitBash.exe terminal and type: $ npm bin -g打开 gitBash.exe 终端并输入: $ npm bin -g

  2. Copy the Path: C:\\Users\\YourMachineName\\AppData\\Roaming\\npm复制路径: C:\\Users\\YourMachineName\\AppData\\Roaming\\npm

5.Click the search icon and type Environment... 5.单击搜索图标并输入环境...

6.Choose Edit environment variables for your account 6.为您的帐户选择编辑环境变量

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

  1. Go back to Your code Editor, or another terminal and test the work.返回您的代码编辑器或其他终端并测试工作。
  2. There is a probability that Powershell will not work. Powershell 有可能无法工作。 That is why you should select GitBash as your default terminal if you develop a website using VSCode on Windows.这就是为什么如果你在 Windows 上使用 VSCode 开发网站,你应该选择 GitBash 作为你的默认终端。 在此处输入图片说明

Just try to use live-server in your project as a dev-dependency.只需尝试在您的项目中使用 live-server 作为开发依赖项。 Yes, it is not the recommended way.是的,这不是推荐的方式。 But it is a shortcut and will save your precious time.但这是一条捷径,可以节省您的宝贵时间。

My npm live-server works well until it suddenly stopped without any error.我的 npm 实时服务器运行良好,直到它突然停止而没有任何错误。 I then must change to use live-server of Visual Studio code instead.然后我必须改为使用 Visual Studio 代码的实时服务器。 After read many article i found that my path variable missing C:\Windows\System32\ variable.阅读许多文章后,我发现我的路径变量缺少 C:\Windows\System32\ 变量。 Check carefully your path environment variable to make sure you have all the addresses needed.仔细检查您的路径环境变量以确保您拥有所需的所有地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM