简体   繁体   English

如何 rest 前缀:npm 配置设置前缀 /usr/local

[英]how to rest prefix: npm config set prefix /usr/local

I was trouble shooting the " ionic: command not found " issue.我在解决“ ionic: command not found ”问题时遇到了麻烦。

I found posts suggesting to try: npm config set prefix /usr/local .我发现建议尝试的帖子: npm config set prefix /usr/local

But I typed " npm config set prefix /usr/loca " on accident.但是我偶然输入了“ npm config set prefix /usr/loca ”。

Now if I try to run any npm command it will just throw errors:现在,如果我尝试运行任何 npm 命令,它只会抛出错误:

Error: EPERM: operation not permitted, mkdir '/usr/loca'
TypeError: Cannot read property 'get' of undefined
    at errorMessage (/usr/local/lib/node_modules/npm/lib/utils/error-message.js:38:39)
    at errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:201:13)
    at /usr/local/lib/node_modules/npm/bin/npm-cli.js:78:20
    at cb (/usr/local/lib/node_modules/npm/lib/npm.js:225:22)
    at /usr/local/lib/node_modules/npm/lib/npm.js:263:24
    at /usr/local/lib/node_modules/npm/lib/config/core.js:81:7
    at Array.forEach (<anonymous>)
    at /usr/local/lib/node_modules/npm/lib/config/core.js:80:13
    at f (/usr/local/lib/node_modules/npm/node_modules/once/once.js:25:25)
    at afterExtras (/usr/local/lib/node_modules/npm/lib/config/core.js:171:20)
/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:97
  var doExit = npm.config.loaded ? npm.config.get('_exit') : true
                          ^

TypeError: Cannot read property 'loaded' of undefined
    at exit (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:97:27)
    at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:216:3)
    at process.emit (events.js:210:5)
    at process._fatalException (internal/process/execution.js:150:25)

Is there any way to fix that?有没有办法解决这个问题?

Thanks a ton!万分感谢!

you can replace the whitespace in your username string after space with "~1".您可以将用户名字符串中的空格替换为“~1”。

npm config set cache "C:\Users\Firstname~1\AppData\Roaming\npm-cache" --global

Hope this will help you.希望这会帮助你。 Happy Coding:)快乐编码:)

Took me about 2 hours to figure this out.我花了大约 2 个小时才弄清楚这一点。 Thought it might help people who are facing a similar issue.认为它可能会帮助面临类似问题的人。

The problem is with:问题在于:

% npm config set prefix /usr/loca

As you can notice from the above, I forgot the letter 'l' at the end of the line leading to npm config setting my 'prefix' to /usr/loca [this is my understanding of the issue.正如您从上面所注意到的,我忘记了导致 npm 配置将我的“前缀”设置为/usr/loca的行末尾的字母“l”[这是我对这个问题的理解。 Feel free to correct me as I am new to Node world]请随时纠正我,因为我是 Node 世界的新手]

Now, when I try and run -现在,当我尝试运行时 -

% npx create-react-app myApp

I got an error as -我收到一个错误 -

Error: EPERM: operation not permitted, mkdir '/usr/loca'错误:EPERM:不允许操作,mkdir '/usr/loca'

Because there is no directory by name 'loca'.因为没有名为“loca”的目录。 Few suggestions about disabling SIP to make it work are there but I think it's not a good idea.关于禁用 SIP 以使其工作的建议很少,但我认为这不是一个好主意。 Anyway, here are the steps I took to resolve the issue -无论如何,这是我为解决问题而采取的步骤 -

Step 1: On your terminal get into root account by typing --> sudo -I第 1 步:在您的终端上通过键入 --> sudo -I 进入 root 帐户

Step 2: Enter your root credential password第 2 步:输入您的根凭证密码

Step 3: Clear npm cache by force --> npm cache clean --force第三步:强制清除 npm 缓存 --> npm 缓存清除 --force

Step 4: Install latest npm --> npm install -g npm@latest --force第四步:安装最新的 npm --> npm install -g npm@latest --force

Step 5: Clear npm cache again --> npm cache clean --force第五步:再次清除 npm 缓存 --> npm 缓存清除 --force

Step 6: You should be good now.第6步:你现在应该很好了。 Check your npm version --> rpm -v检查您的 npm 版本 --> rpm -v

Step 7: 'exit' out of root第 7 步:“退出”根目录

Step 8: Set prefix properly this time --> npm config set prefix /usr/local第八步:这次正确设置前缀 --> npm config set prefix /usr/local

Step 9: npx create-react-app client第 9 步:npx create-react-app 客户端

Step 10: Type 'Y' to install create-react-app package第 10 步:输入“Y”以安装 create-react-app package

If everything went well, you should see a 'Happy Hacking' message as the last line.如果一切顺利,您应该会在最后一行看到“Happy Hacking”消息。

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

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