Javascript npm 安装时出现错误“ETXTBSY:文本文件正忙”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45678817/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 03:10:06  来源:igfitidea点击:

error "ETXTBSY: text file is busy" on npm install

javascriptnode.jslaravelnpmhomestead

提问by Martijn Imhoff

When running npm install [any package]or even npm installon homestead I get the following error:

在运行npm install [any package]或什至npm install在宅基地上时,我收到以下错误:

npm ERR! ETXTBSY: text file is busy, rmdir '/home/vagrant/valemus-shop-starter/valemus-shop/node_modules/fsevents'

Debug log can be seen here

调试日志可以在这里看到

  • Box 'laravel/homestead' (v3.0.0)
  • Node: v8.2.1
  • NPM: 5.3.0
  • 框 'laravel/homestead' (v3.0.0)
  • 节点:v8.2.1
  • NPM:5.3.0

I tried removing the fseventsdirectory, however, it doesn't exist.

我尝试删除该fsevents目录,但是,它不存在。

How do I fix this?

我该如何解决?

采纳答案by kpratihast

Downgraing the npm version to 5.7.1 did the trick for me.

将 npm 版本降级到 5.7.1 对我有用。

Command used to downgrade: npm install -g [email protected]

用于降级的命令: npm install -g [email protected]

I am using Win10, Vagrant, Ubuntu v14.04 and Node v8.11.4

我使用的是 Win10、Vagrant、Ubuntu v14.04 和 Node v8.11.4

回答by Babak Bandpey

I ran into the same thing on Windows 10 + VirtualBox (VBox) + Vagrant + Laravel Homestead when I wanted to change to react frontend.

当我想更改为响应前端时,我在 Windows 10 + VirtualBox (VBox) + Vagrant + Laravel Homestead 上遇到了同样的事情。

And after much search and trial and error, this solution worked for me, maybe it works for you as well.

经过大量的搜索和反复试验,这个解决方案对我有用,也许对你也有用。

Halted the vagrant:

停止流浪者:

vagrant halt

Added the following into the configure section of the Vagrantfile in the Homestead dir

将以下内容添加到 Homestead 目录中 Vagrantfile 的配置部分

  config.vm.provider "virtualbox" do |v|
        v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
  end

started the cmd as admin

以管理员身份启动cmd

then vagrant up

然后 vagrant up

and vagrant ssh

vagrant ssh

cd to development dir

cd到开发目录

then removed the node_modules dir by rm -rf node_modules/if any

然后删除 node_modules 目录,rm -rf node_modules/如果有的话

and then ran the sudo npm install && npm run dev

然后运行 sudo npm install && npm run dev

and the whole thing was installed without any warnings or errors.

整个安装过程没有任何警告或错误。

This is the result of two hours reading :)

这是两个小时阅读的结果:)

Edit:

编辑:

If your problem is not solved and you have the mentioned setup you can use another solution:

如果您的问题没有解决并且您有提到的设置,您可以使用另一种解决方案:

Install the Node on your windows machine too

也在你的 Windows 机器上安装 Node

Then cd to your development directory and run the npm installfrom the Windows and the you'll have the same result.

然后 cd 到您的开发目录并npm install从 Windows运行,您将获得相同的结果。

You can also initiate the npm run watchfrom a windows cmd afterwards.

之后您也可以npm run watch从 Windows cmd启动。

This helped me to lift the load from the VM and let the Windows do the watch and receive the notifications of the npm run watchin Windows.

这帮助我解除了 VM 的负载,让 Windows 进行监视并接收npm run watchWindows 中的通知。

Cheers

干杯

回答by Wilson Wang

Just issue "npm install" in Windows instead of in Homestead. Of course, you need to have npm for windows installed to do that.

只需在 Windows 中而不是在 Homestead 中发出“npm install”。当然,你需要安装 npm for windows 才能做到这一点。

回答by Hayreddin Tüzel

I struggled with this problem on my Windows 10 machine with Homestead a lot of. And After a lot of effort I solved it with that way;

我在我的 Windows 10 机器上用 Homestead 解决了这个问题。经过一番努力,我用这种方式解决了它;

delete your node_modules folder.

删除您的 node_modules 文件夹。

You run this commands on your windows terminal:

您在Windows 终端上运行此命令

npm install --no-bin-links (After some experience it is necessary for virtual machines)
npm rebuild --no-bin links

Generally it works after these commands, but if you have take this error

通常它在这些命令之后工作,但如果你有这个错误

"Node Sass could not find a binding for your current environment:"

“Node Sass 无法为您当前的环境找到绑定:”

please run this command on your Homestead Terminalfor installing node Sass for Linux.

请在你的Homestead 终端上运行这个命令来安装节点 Sass for Linux。

npm rebuild node-sass

if it is not work, try use yarn. Delete node modules folder package.json.lock and yarn.lock (if there) files and type

如果它不起作用,请尝试使用纱线。删除节点模块文件夹 package.json.lock 和 yarn.lock(如果有)文件并输入

yarn install

If all of them is not save you, use all npm commands out of the virtual machine.It will be work.

如果所有这些都无法拯救您,请使用虚拟机之外的所有 npm 命令。这将是工作。

I hope this helps you...

我希望这可以帮助你...

回答by horikeso

The same thing happened to me

这样的事情我也经历过

My environment is linux

我的环境是linux

fsevents is a module dedicated to mac

fsevents 是一个专用于 mac 的模块

Please try the following command

请尝试以下命令

npm install --no-optional

npm install --no-optional

回答by Azhar Khattak

I was still getting an error, even after doing following

即使在执行以下操作后,我仍然遇到错误

  config.vm.provider "virtualbox" do |v|
    v.customize ["setextradata", :id, 
     "VBoxInternal2/SharedFoldersEnableSymlinksCreate/v-root", "1"]
  end

as suggested by Babak Bandpey

正如Babak Bandpey所建议的

It turned out that there was another annoying problem of file path character limit. This happens quite often if you are using a node module with long name. You can easily solve this by following these steps after vagrant ssh into linux vm:

原来还有一个烦人的文件路径字符限制问题。如果您使用具有长名称的节点模块,这种情况经常发生。在 vagrant ssh 进入 linux vm 后,您可以通过以下步骤轻松解决此问题:

  1. Create ‘node_modules' folder in your home folder mkdir ~/node_modules
  2. Add symbolic link to the ‘node_modules' folder you just created inside your project folder

    ln -sf ~/node_modules /vagrant/your-project-folder

  1. 在您的主文件夹中创建“node_modules”文件夹 mkdir ~/node_modules
  2. 将符号链接添加到您刚刚在项目文件夹中创建的“node_modules”文件夹

    ln -sf ~/node_modules /vagrant/your-project-folder

This solution will ensure that all the node modules are stored inside home directory instead of synced folder. Original source : https://blog.rudylee.com/2014/10/27/symbolic-links-with-vagrant-windows/

此解决方案将确保所有节点模块都存储在主目录而不是同步文件夹中。原始来源:https: //blog.rudylee.com/2014/10/27/symbolic-links-with-vagrant-windows/

Hope it helps somone having similar issue, thanks!

希望能帮到有类似问题的朋友,谢谢!

回答by Janet W.

I had problem with "npm install" too, I use Windows 10. Finally I got it fixed, what I did is that I exited from "vagrant ssh" and run "vagrant box update", then "npm install" worked. Notice that I ran "vagrant box update" and "npm install" out of "vagrant ssh". Hope it helps.

我也遇到了“npm install”的问题,我使用的是 Windows 10。最后我把它修好了,我所做的是从“vagrant ssh”退出并运行“vagrant box update”,然后“npm install”工作。请注意,我从“vagrant ssh”运行了“vagrant box update”和“npm install”。希望能帮助到你。

回答by XFaramir

I also struggle finding a solution for this but here it is.

我也很难为此找到解决方案,但它就在这里。

  1. Make sure to update node to latest version
  1. 确保将节点更新到最新版本

To update, you can install n

要更新,您可以安装 n

sudo npm install -g n

Then just :

然后只是:

sudo n latest
  1. Set Node scripts to use environment variables across platforms
  1. 设置 Node 脚本以跨平台使用环境变量

In vagrant run :

在流浪者中运行:

npm install --save-dev cross-env
npm install 
npm run dev 

That did the trick , although i spent an entire day finding the right solution (https://www.npmjs.com/package/cross-env)

虽然我花了一整天的时间找到了正确的解决方案 ( https://www.npmjs.com/package/cross-env) ,但这确实奏效了

回答by Jayakusuma

i had to delete the node_modules folder first, then i did

我必须先删除 node_modules 文件夹,然后才删除

sudo chmod a+x .

for making sure i got the privilege to do anything on the machine, then i

为了确保我有特权在机器上做任何事情,然后我

sudo npm install --no-bin-links

no bin links is required in vagrant from my experience because these VM don't support bin links (correct me if im wrong). Then i just

根据我的经验,vagrant 不需要 bin 链接,因为这些 VM 不支持 bin 链接(如果我错了,请纠正我)。然后我只是

sudo npm run dev

at this point some people might encounter no cross-env found error. In that case, just delete cross-env in package.json file and run it again. It worked for me but some people still encounter the same problem. Might worth to give it a shot.

此时有些人可能会遇到 no cross-env found 错误。在这种情况下,只需删除 package.json 文件中的 cross-env 并再次运行它。它对我有用,但有些人仍然遇到同样的问题。可能值得试一试。