Javascript webpack --watch 不编译更改的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26708205/
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-22 23:15:35  来源:igfitidea点击:

webpack --watch isn't compiling changed files

javascriptwebpackfsevents

提问by alcedo

I tried running webpack --watchand after editing my JS files, it doesn't trigger an auto-recompilation.

我尝试运行webpack --watch,在编辑我的 JS 文件后,它不会触发自动重新编译。

I've tried reinstalling webpackusing npm uninstallbut it's still not working.

我已经尝试webpack使用重新安装,npm uninstall但它仍然无法正常工作。

Any ideas?

有任何想法吗?

采纳答案by Ben Mosher

FYI: it seems OS X can have a folder get corrupted and no longer send fsevents(which watchpack/chokidar/Finder uses) for itself and any child folders. I can't be sure this is what happened to you, but it was very frustrating for me and a colleague.

仅供参考:似乎 OS X 可能有一个文件夹被损坏并且不再为它自己和任何子文件夹发送fsevents(它watchpack/ chokidar/Finder 使用)。我不能确定这是发生在你身上的事情,但这对我和一位同事来说非常令人沮丧。

We were able to rename the corrupt parent folder and then watch events immediately came through as expected. See this blog post for more info: http://feedback.livereload.com/knowledgebase/articles/86239-os-x-fsevents-bug-may-prevent-monitoring-of-certai

我们能够重命名损坏的父文件夹,然后按预期立即观察事件。有关更多信息,请参阅此博客文章:http: //feedback.livereload.com/knowledgebase/articles/86239-os-x-fsevents-bug-may-prevent-monitoring-of-certai

The recommended fixes from the above link are:

上面链接中推荐的修复方法是:

  • rebooting the computer
  • checking the disk and repairing permissions via Disk Utility
  • adding the folder to Spotlight privacy list (the list of folders to not index), and then removing from it, effectively forcing a reindexing
  • renaming the folder, and then possibly renaming it back
  • re-creating the folder and moving the old contents back into it
  • 重新启动计算机
  • 通过磁盘工具检查磁盘和修复权限
  • 将文件夹添加到 Spotlight 隐私列表(未索引的文件夹列表),然后从中删除,有效地强制重新索引
  • 重命名文件夹,然后可能将其重命名
  • 重新创建文件夹并将旧内容移回其中

First two did not work for us, didn't try the Spotlight suggestion, and the re-creation did not prove necessary.

前两个对我们不起作用,没有尝试 Spotlight 的建议,重新创建也没有必要。

We were able to find the root problem folder by opening Finder and creating files in each successive parent folder until one showed up immediately (since Finder will get hosed by this bug as well). The root-most folder that does not update is the culprit. We just mv'd it and mv'd it back to its original name, and then the watcher worked.

我们能够通过打开 Finder 并在每个连续的父文件夹中创建文件来找到根本问题文件夹,直到一个文件立即出现(因为 Finder 也会被这个错误感染)。不更新的最根目录文件夹是罪魁祸首。我们只是mvmv它改回原来的名字,然后观察者工作了。

No idea what causes the corruption, but I'm just glad to have a fix.

不知道是什么导致了损坏,但我很高兴能解决这个问题。

回答by César D. Velandia

If your code isn't being recompiled, try increasing the number of watchers (in Ubuntu):

如果您的代码没有被重新编译,请尝试增加观察者的数量(在 Ubuntu 中):

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

Source: https://webpack.github.io/docs/troubleshooting.html

来源:https: //webpack.github.io/docs/troubleshooting.html

回答by CoderBriggs

Adding the following code to my webpack configuration file fixed the issue for me, hope this helps. Don't forget to ignore your node_modules folder, as that would kill performance for HMR (Hot Module Replacement):

将以下代码添加到我的 webpack 配置文件中为我解决了这个问题,希望这会有所帮助。不要忘记忽略您的 node_modules 文件夹,因为这会降低 HMR(热模块更换)的性能:

watchOptions: {
  poll: true,
  ignored: /node_modules/
}

回答by Chris

I have had this problem when working with WebStorm.

我在使用 WebStorm 时遇到了这个问题。

Disabling Settings -> System Settings -> "safe write"resolved it for me.

禁用设置 -> 系统设置 ->“安全写入”为我解决了这个问题。

Found the recommendation to do so in: WebPack Troubleshooting

WebPack 故障排除中找到了这样做的建议

回答by Les

Just to add to possible solutions: I had my project folder inside a Dropbox folder, moving it out solved the problem for me. (OS X)

只是添加到可能的解决方案中:我将项目文件夹放在 Dropbox 文件夹中,将其移出为我解决了问题。(OS X)

回答by Liam Horne

One issue is that if your path names aren't absolute then things like this will happen. I had accidentally set resolve.rootto ./instead of __dirnameand this caused me to waste a lot of time deleting and re-creating files like the guys above me.

一个问题是,如果您的路径名不是绝对的,那么这样的事情就会发生。我不小心设置resolve.root./而不是,__dirname这导致我浪费了大量时间删除和重新创建文件,就像我上面的人一样。

回答by Acker Apple

Folder case sensitivity was my issue. My code calls to require() had all lowercase path names BUT the actually directories had an uppercase letter in them. I renamed all my directories to lowercase and webpack watching worked instantly.

文件夹区分大小写是我的问题。我对 require() 的代码调用具有全部小写路径名,但实际目录中有一个大写字母。我将所有目录重命名为小写,webpack 监视立即生效。

回答by Angelo Selvini

If changing fs.inotify.max_user_watches as pointend out by César still doesn't work try to use polling instead of native watchers by creating your script as shown in the docsor running webpack with --watch --watch-polloptions.

如果 César 指出更改 fs.inotify.max_user_watches 仍然不起作用,请尝试通过创建您的脚本(如文档中所示)或使用--watch --watch-poll选项运行 webpack来使用轮询而不是本机观察者。

回答by Alberto Oliveira

Work for me in Laravel Homestead

在 Laravel Homestead 为我工作

--watch --watch-poll

回答by mk8374876

Note that if you run webpack within a virtual machine (Vagrant / Virtualbox) and you change your files on the host platform, file updates in the shared folder may not trigger inotify on Ubuntu. That will cause the changes to not be picked up by webpack.

请注意,如果您在虚拟机 (Vagrant / Virtualbox) 中运行 webpack 并更改主机平台上的文件,则共享文件夹中的文件更新可能不会在 Ubuntu 上触发 inotify。这将导致 webpack 无法获取更改。

see: Virtualbox ticket #10660

请参阅:Virtualbox 票 #10660

In my case, editing and saving the file on de guest (in vi) did trigger webpack. Editing it on the host (in PhpStorm, Notepad or any other application) dit NOT trigger webpack whatever I did.

就我而言,在 de guest(在 vi 中)上编辑和保存文件确实触发了 webpack。在主机上编辑它(在 PhpStorm、记事本或任何其他应用程序中)并不会触发 webpack,无论我做什么。

I solved it by using vagrant-fsnotify.

我通过使用vagrant-fsnotify解决了它。