简体   繁体   English

无法运行任何npm全局命令

[英]cannot run any npm global command

I cannot run any of my npm global commands. 我无法运行任何npm全局命令。

The root of my global files are at /Users/Alex/.npm-packages/lib/node_modules . 我的全局文件的根目录位于/Users/Alex/.npm-packages/lib/node_modules I obtained this from running npm -g root 我是从运行npm -g root

I am trying to run create-react-app <filename> . 我正在尝试运行create-react-app <filename> Create React App is located at /Users/Alex/.npm-packages/lib/node_modules/create-react-app . Create React App位于/Users/Alex/.npm-packages/lib/node_modules/create-react-app I can run node createReactApp.js from this directory and spawn a project, however this is very inconvenient. 我可以从该目录运行node createReactApp.js并生成一个项目,但这非常不方便。

When I run create-react-app in shell I get zsh: command not found: create-react-app . 当我在shell中运行create-react-app ,我得到了zsh: command not found: create-react-app So I decided to modify my .bash_profile . 因此,我决定修改.bash_profile Currently it looks like this: 当前看起来像这样:

export PATH="/usr/local/bin:$PATH"

# NPM
export PATH="$HOME/.npm-packages/bin/:$PATH"
export PATH="$HOME/.npm-packages/lib/node_modules:$PATH"

#Create Reac App
export PATH="$HOME/.npm-packages/lib/node_modules/create-react-app:$PATH"

and I still cannot run any of my npm global commands. 而且我仍然无法运行任何npm全局命令。

How can I run my npm global commands like create-react-app <filename> ? 如何运行npm全局命令(如create-react-app <filename> I've been scratching my head for about 40 minutes trying different things, reading various blogs, and numerous github tickets, various stack overflow questions and I still cannot solve this npm problem. 我花了大约40分钟时间尝试各种不同的东西,阅读各种博客和大量的github票,各种堆栈溢出问题,但我仍然无法解决这个npm问题。

UPDATE 更新

I've included the following to my .bash_profile and then ran source .bash_profile to update my $PATH 我将以下内容包含到我的.bash_profile ,然后运行source .bash_profile更新了我的$PATH

PATH=/usr/bin:/bin:/usr/sbin:/sbin
export PATH
PATH=/usr/local/bin:/usr/local/sbin:"$PATH"
PATH=/opt/local/bin:/opt/local/sbin:"$PATH"
...

Now my global commands work. 现在,我的全局命令起作用了。

Have you looked into the folder and see if the global npm commands are there? 您是否已查看文件夹,并查看是否存在全局npm命令? If it does, you can just include /Users/Alex/.npm-packages/bin to your $PATH and it should solve the problem. 如果是这样,则只需将/Users/Alex/.npm-packages/bin包含到$ PATH中,它就可以解决问题。 Otherwise, there is a possibility that you have installed the global packages incorrectly. 否则,可能会错误地安装了全局软件包。 Hope it helps! 希望能帮助到你!

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

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