简体   繁体   English

npm 安装在 Windows 中不起作用

[英]npm install not working in windows

I have no idea what is happening here.我不知道这里发生了什么。 Hoping someone can help me.希望有人可以帮助我。

This works great in my mac.这在我的 Mac 上非常有效。 But same process in Windows and npm install crashes.但是 Windows 和 npm install 中的相同过程崩溃了。 This is what I get.这就是我得到的。

EDIT编辑

I've tried everything I've seen in SO so far and every link Google search produced.到目前为止,我已经尝试了我在 SO 中看到的所有内容以及 Google 搜索生成的每个链接。 I tried the following as suggested here :我按照此处的建议尝试了以下操作:

rm -rf node_modules
npm install

Didn't work没用

Ran it as admin,以管理员身份运行它,

tried npm install -g试过 npm install -g

re-started xampp server重新启动 xampp 服务器

turned off Windows defender关闭 Windows Defender

checked the PATH for C:\\Program Files\\nodejs检查 C:\\Program Files\\nodejs 的 PATH

Short of throwing this POS Windows threw a window, pun intended, I've done everything.没有扔这个 POS Windows 扔了一个窗口,双关语意为,我已经做了一切。 Hail Apple!苹果万岁!

warn optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules\chokidar\node_modules\fsevents):
warn notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.0.17: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid OS:    darwin
verbose notsup SKIPPING OPTIONAL DEPENDENCY: Valid Arch:  any
verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual OS:   win32
verbose notsup SKIPPING OPTIONAL DEPENDENCY: Actual Arch: x64
warn fuse@1.4.4 No description
verbose If you need help, you may report this error at:
verbose     <https://github.com/npm/npm/issues>
warn fuse@1.4.4 No repository field.
verbose If you need help, you may report this error at:
verbose     <https://github.com/npm/npm/issues>
warn fuse@1.4.4 No license field.
verbose If you need help, you may report this error at:
verbose     <https://github.com/npm/npm/issues>
verbose stack Error: EPERM: operation not permitted, rename 'C:\xampp\htdocs\ScalaCM\node_modules\.staging\accessibility-developer-tools-2e33f290' -> 'C:\xampp\htdocs\ScalaCM\node_modules\accessibility-developer-tools'
verbose stack     at destStatted (C:\Users\Luis\AppData\Roaming\npm\node_modules\npm\lib\install\action\finalize.js:25:7)
verbose stack     at C:\Users\Luis\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\polyfills.js:276:29
verbose stack     at FSReqWrap.oncomplete (fs.js:123:15)
verbose stack
verbose stack Error: EPERM: operation not permitted, rename 'C:\xampp\htdocs\ScalaCM\node_modules\.staging\accessibility-developer-tools-2e33f290' -> 'C:\xampp\htdocs\ScalaCM\node_modules\accessibility-developer-tools'
verbose stack     at Error (native)
verbose cwd C:\xampp\htdocs\ScalaCM
error Windows_NT 10.0.14393
error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Luis\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install"
error node v6.9.1
error npm  v4.0.2
error path C:\xampp\htdocs\ScalaCM\node_modules\.staging\accessibility-developer-tools-2e33f290
error code EPERM
error errno -4048
error syscall rename
error Error: EPERM: operation not permitted, rename 'C:\xampp\htdocs\ScalaCM\node_modules\.staging\accessibility-developer-tools-2e33f290' -> 'C:\xampp\htdocs\ScalaCM\node_modules\accessibility-developer-tools'
error     at destStatted (C:\Users\Luis\AppData\Roaming\npm\node_modules\npm\lib\install\action\finalize.js:25:7)
error     at C:\Users\Luis\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\polyfills.js:276:29
error     at FSReqWrap.oncomplete (fs.js:123:15)
error
error Error: EPERM: operation not permitted, rename 'C:\xampp\htdocs\ScalaCM\node_modules\.staging\accessibility-developer-tools-2e33f290' -> 'C:\xampp\htdocs\ScalaCM\node_modules\accessibility-developer-tools'
error     at Error (native)
error  { Error: EPERM: operation not permitted, rename 'C:\xampp\htdocs\ScalaCM\node_modules\.staging\accessibility-developer-tools-2e33f290' -> 'C:\xampp\htdocs\ScalaCM\node_modules\accessibility-developer-tools'
error     at destStatted (C:\Users\Luis\AppData\Roaming\npm\node_modules\npm\lib\install\action\finalize.js:25:7)
error     at C:\Users\Luis\AppData\Roaming\npm\node_modules\npm\node_modules\graceful-fs\polyfills.js:276:29
error     at FSReqWrap.oncomplete (fs.js:123:15)
error
error Error: EPERM: operation not permitted, rename 'C:\xampp\htdocs\ScalaCM\node_modules\.staging\accessibility-developer-tools-2e33f290' -> 'C:\xampp\htdocs\ScalaCM\node_modules\accessibility-developer-tools'
error     at Error (native) parent: 'fuse' }
error Please try running this command again as root/Administrator.
verbose exit [ -4048, true ]

node -v gives me a version v6.9.1 node -v 给我一个版本 v6.9.1

npm -v gives me a version as well 4.0.2 npm -v 也给了我一个版本 4.0.2

Which proves they are all installed fine, am I right?这证明它们都安装得很好,对吗?

After countless hours of debugging and researching, I decided to install in a different machine to see if the problem was with my Node installation.经过无数个小时的调试和研究,我决定安装在另一台机器上,看看问题是否出在我的 Node 安装上。 It worked.有效。

So for everyone who may come across this, know that the possibility to uninstall node and delete NPM will be there.因此,对于可能遇到此问题的每个人,都知道卸载节点和删除 NPM 的可能性将存在。 This is what I did.这就是我所做的。 I believe it is the safest way to solve the problem and all the rest of your applications installed in your machine will still work.我相信这是解决问题的最安全方法,并且您机器中安装的所有其他应用程序仍然可以工作。 I credit this answer for these steps, although I had other npm and node_modules in other locations.我将这些步骤归功于这个答案,尽管我在其他位置有其他 npm 和 node_modules。 So do a quick search for these and unless they are part of an application, make sure they are deleted as well.因此,请快速搜索这些内容,除非它们是应用程序的一部分,否则请确保它们也被删除。

  1. Uninstall from Programs & Features with the uninstaller.使用卸载程序从程序和功能中卸载。

  2. Reboot (or you probably can get away with killing all node-related processes from Task Manager).重新启动(或者您可能可以从任务管理器中杀死所有与节点相关的进程)。

  3. Look for these folders and remove them (and their contents) if any still exist.查找这些文件夹并删除它们(及其内容)(如果仍然存在)。 Depending on the version you installed, UAC settings, and CPU architecture, these may or may not exist:根据您安装的版本、UAC 设置和 CPU 架构,这些可能存在也可能不存在:

    • C:\\Program Files (x86)\\Nodejs
    • C:\\Program Files\\Nodejs
    • C:\\Users\\{User}\\AppData\\Roaming\\npm (or %appdata%\\npm ) C:\\Users\\{User}\\AppData\\Roaming\\npm (或%appdata%\\npm
    • C:\\Users\\{User}\\AppData\\Roaming\\npm-cache (or %appdata%\\npm-cache ) C:\\Users\\{User}\\AppData\\Roaming\\npm-cache (或%appdata%\\npm-cache
    • C:\\Users\\{User}\\.npmrc (and possibly check for that without the . prefix too) C:\\Users\\{User}\\.npmrc (也可能检查没有.前缀)
  4. Check your %PATH% environment variable to ensure no references to Nodejs or npm exist. 检查您的%PATH%环境变量以确保不存在对Nodejsnpm引用。

  5. If it's still not uninstalled, type where node at the command prompt and you'll see where it resides -- delete that (and probably the parent directory) too.如果它仍未卸载,请在命令提示符下键入where node ,您将看到它所在的位置——也删除它(可能还有父目录)。

  6. Reboot, for good measure.重新启动,很好的措施。

Please read the error carefully.请仔细阅读错误。 It's saying :它说:

fsevents@1.0.17: wanted {"os":"darwin","arch":"any"}

The FSEvents API in OS X allows applications to register for notifications of changes to a given directory tree. OS X 中的 FSEvents API 允许应用程序注册给定目录树的更改通知。

It needs OS X, Because some of npm dependencies are using fsevents that's by It's breaking in windows.它需要 OS X,因为一些 npm 依赖项正在使用 fsevents,它在 Windows 中被破坏了。

https://github.com/strongloop/fsevents https://github.com/strongloop/fsevents

Update:更新:

As you told It's working without fsevents then you can follow these steps:正如您所说,它可以在没有 fsevents 的情况下工作,那么您可以按照以下步骤操作:

install npm-check-updates and try again.安装npm-check-updates 并重试。

 npm install -g npm-check-updates
 ncu -u       #It will update the npm dependencies.
 rm -fr node_modules
 npm install

It will update the dependencies and install the dependencies.它将更新依赖项并安装依赖项。
Hope It will work :)希望它会起作用:)

please try to open the console as a administrator.请尝试以管理员身份打开控制台。 do right Click on the commandLine and select "open as administrator" then try installing dependency.右键单击命令行并选择“以管理员身份打开”,然后尝试安装依赖项。

update and then install again更新然后重新安装

npm install -g npm-check-updates

npm install

add this to fix any errors添加此项以修复任何错误

npm audit fix npm 审计修复

唯一对我有用的解决方案是从 C:\\Users(your username)\\AppData\\Roaming 中删除 npm 和 npm-cache 卸载 nodejs 并重新安装它

I tried to disabled all my antivirus and firewall, clear npm cache, and do cache verify but nothing works.我试图禁用我所有的防病毒和防火墙,清除 npm 缓存,并进行缓存验证,但没有任何效果。 The only thing that works on my end is to install the Node Version Manager nvm .唯一对我nvm是安装 Node Version Manager nvm

How Node Version Manager works?节点版本管理器如何工作?

Permission errors can occur when packages are installed globally.全局安装软件包时可能会发生权限错误。 If this is the case, npm may need to be set up to operate without elevated permissions.如果是这种情况,可能需要将 npm 设置为在没有提升权限的情况下运行。 This where nvm comes in. It lets you install a different node version without triggering the administrative access.这就是 nvm 的用武之地。它允许您安装不同的节点版本,而无需触发管理访问权限。

  1. If you have existing Node installed, I recommend uninstalling it like the process given by LOTUSMS above如果你已经安装了现有的 Node,我建议像上面 LOTUSMS 给出的过程一样卸载它

Uninstall from Programs & Features with the uninstaller.使用卸载程序从程序和功能中卸载。

Reboot (or you probably can get away with killing all node-related processes from Task Manager).重新启动(或者您可能可以从任务管理器中杀死所有与节点相关的进程)。

Look for these folders and remove them (and their contents) if any still exist.查找这些文件夹并删除它们(及其内容)(如果仍然存在)。 Depending on the version you installed, UAC settings, and CPU architecture, these may or may not exist:根据您安装的版本、UAC 设置和 CPU 架构,这些可能存在也可能不存在:

C:\\Program Files (x86)\\Nodejs C:\\Program Files\\Nodejs C:\\Program Files (x86)\\Nodejs C:\\Program Files\\Nodejs

C:\\Users{User}\\AppData\\Roaming\\npm (or %appdata%\\npm) C:\\Users{User}\\AppData\\Roaming\\npm(或 %appdata%\\npm)

C:\\Users{User}\\AppData\\Roaming\\npm-cache (or %appdata%\\npm-cache) C:\\Users{User}\\AppData\\Roaming\\npm-cache(或 %appdata%\\npm-cache)

C:\\Users{User}.npmrc (and possibly check for that without the . prefix too) Check your %PATH% environment variable to ensure no references to Nodejs or npm exist. C:\\Users{User}.npmrc(也可能检查没有 . 前缀的情况)检查您的 %PATH% 环境变量以确保不存在对 Nodejs 或 npm 的引用。

If it's still not uninstalled, type where node at the command prompt and you'll see where it resides -- delete that (and probably the parent directory) too.如果它仍未卸载,请在命令提示符下键入 where node,您将看到它所在的位置——也删除它(可能还有父目录)。

  1. Install nvm here - https://github.com/coreybutler/nvm-windows .在此处安装 nvm - https://github.com/coreybutler/nvm-windows or you can use curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash或者你可以使用curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash

  2. Run nvm or command -v nvm .运行nvmcommand -v nvm If something prints, the installation was successful.如果有打印,则安装成功。

  3. Install prefered node version - eg nvm use 16.3.0安装首选节点版本 - 例如nvm use 16.3.0

  4. Check if the node and npm are properly install.检查 node 和 npm 是否安装正确。 Just run node -v and npm -v只需运行node -vnpm -v

  5. Enjoy npm installation :D享受 npm 安装 :D

If npm install is not not working, then you can use this command-如果 npm install 不起作用,那么您可以使用此命令-

 npm install --legacy-peer-deps

This works for me.这对我有用。

如果您使用 nvm 安装了 node 和 npm,那么您可以使用nvm uninstall 5.5.5卸载它,然后使用nvm install 5.5.5重新安装,这解决了我的问题,我不必进入并删除模块或更改路径

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

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