找不到窗口

我在尝试使用 bower (安装 foundation 5)或在命令行上获取任何与工作相关的 bower 时遇到了很大的问题。

我安装了

  • 红宝石1.9.3
  • Git (带有从命令提示符运行选项)
  • Nodejs

我成功逃跑了

npm install -g bower grunt-cli
gem install foundation

这些都运行良好。我已经在 npm/node_modules目录中查看,我可以看到 bower文件夹在那里。

每次我输入 bower无论是在 cmdruby cmdgit bash我得到

命令无法识别

我已经在环境变量中设置了 git 路径。

讨厌的是凉亭上的说明,上面写着:

npm install -g bower
bower install

这不管用!

100289 次浏览

Same issue. I solved it by using another version of bower. It works when i tried to use version 1.2.6

$ npm install -g bower@1.2.6

I bumped into this problem after npm install -g bower too. I solved the problem by adding npm's binary folder to my path.

Here are some helpful hints for doing that:

  1. Find the location of your npm global binaries: npm config get prefix. This path may look something like C:\Users\username\AppData\Roaming\npm (or C:\ProgramData\chocolatey\lib\nodejs.commandline.X.XX.XX\tools if you use Chocolatey).
  2. Add the path from step 1 to your Path.

    • Open the Windows Control Panel, search for environment, then click on either edit environment variables for your account, or Edit the system environment variables`.

    • Find the variable named Path or PATH, or create one if it doesn't exist.

    • Paste the path from step 1 here (; delimited).

    • You may need to restart your command prompt window.

  3. You should now be able to enter bower commands.

If above solutions don't work. I think you should specify the absolute path to use the bower in command prompt. In my app folder, I just call

C:\Users\yourusername\AppData\Roaming\npm\bower.cmd install

This is content in my bower.cmd. It looks like my windows can't recognize the ~dp0 variable,

node  "C:\Users\yourusername\AppData\Roaming\npm\node_modules\bower\bin\bower" %*

in case this helps.

I'm a npm / bower nooB - but what happened in my case was, that I was using the Angular JS tutorial, which seems to have bower set up to be used via npm, and NOT via the command line directly.

Note: in my case I think my bower install got messed up. I ran this to fix up my bower install:

npm install -gf bower

Then I edited my bower.json file to add in a new library that I wanted to use (in my case angular-sanitize)

I CD to the location of my project

cd myProjectPath

Then to run bower, I actually used npm install:

npm install

This seems to to run bower as a node package, which in turn scans bower.json and installs any missing bower packages.

To run bower as a npm package, add npm before the bower command:

npm bower -v

hope this helps,

Sean

I had this problem after installing Chocolatey 0.9.8.28. I tried most of the solutions listed here, but I was unable to have 'bower -v' recognized in the Powershell commandline. This seemed a little strange since the Chocolatey Install is 'all about' Powershell. Eventually I was able to succeed by setting the path so that Powershell could find the updated PATH variable settings, but I needed help to understand why and how to do it, which I am providing below:

After failing with Powershell initially, I was able to go to a standard DOS Commandline (not by using cmd /c in powershell) and successfully perform all the variations of path setting that are discussed above and have success in seeing bower and the bower commands recognized by the DOS command line. And the cmd window showed the full updated path (C:\ProgramData\chocolatey\lib\nodejs.commandline.0.10.34\tools) - notice that the version number may change from the listing by the honorable KimchiMan.

This PATH persisted through closing and opening new DOS command line windows, but it was not recognized (ever) in any Powershell windows.

Then I discovered the following related discussion: Set Powershell Path Settings.

This points out that Powershell recognizes the HKLM path settings version when starting up. AND it is possible to set the Path EITHER IN the session (non-persistent) or in the Registry (persistent). The following is directly from that discussion.

These commmands can set the PATH temporarily for a powershell SESSION:

$env:Path = 'New path'
[System.Environment]::SetEnvironmentVariable('Path', 'New Path', 'Process')

These commands can set the PATH permanently for all new Powershell Sessions:

Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Session Manager\Environment' -Name 'Path' -Value 'New Path'
[System.Environment]::SetEnvironmentVariable('Path', 'New Path', 'Machine')

But I've messed with setting registry settings programmatically before and I don't believe a line or two of PS script is at all up to the task. So I did not even try this option.

Instead I went to the Control Panel/System console and changed the path through the Environment Variables dialog. I noticed that all the effort I had made to change the path with set PATH in a DOS commandline had worked during the windows session, but the new path entry had not been persisted to the Environment Variables/Registry even though the Dos session was running as administrator.

After I made this change through the Control Panel, the updated path for bower in Chococlatey's tools folder (and presumably all subsequent tool installs) were permanently set and bower was available in both the DOS command line and in the Powershell command line.

hope this helps...

This definitly will happen if your Windows PATH variable close to 1024 symbol length. So new links such "C:\Users\username\AppData\Roaming\npm" simply won't fit into that.

Check your PATH, remove extra stuff and try to reinstall node.js and bower etc. Also there is a way to increase 1024-length limit

Uninstalled 64bit and Installing 32-bit version of nodejs along with git- 32bit worked!

Had the same issue. I just ran "npm install -g bower" then visited the directory where it was downloaded, in my case the location was "C:\Users\user\AppData\Roaming\npm\node_modules\bower"

From the directory I ran bower, and everything working fine, even from other directory

As others mentioned have to add bower into environment variables, but the easiest way to locate is just simply type in your npm location first, then use Browse File and locate bower on your system(you can search for it in search bar as well), because the location may vary for different users.

sample in my end

1. Type in windows cmd:

for /f %a ('npm config get prefix') do setx path %a

2. Reload cmd