Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/...' #187

Open
Philipp91 opened this issue Jan 4, 2021 · 92 comments

Comments

@Philipp91
Copy link

I run webpack --watch --watch-options-stdin ... and amidst its initial build (not the subsequent builds triggered by changed files), it prints:

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/DumpStack.log.tmp'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/hiberfil.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/pagefile.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/swapfile.sys'

Someone already reported the problem here, so I'll refer to those details for reproduction. Key elements are webpack v5 and WSL1 under Windows.

The directory /mnt/c maps to the Windows root drive C:\, which contains these special files like the swapfile, to which the user doesn't have access. That is, the command ls /mnt/c fails on the command line too. So it's not surprising that it fails for watchpack too.

What is surprising (to me) is that watchpack attempts to list that directory to begin with. I have no config telling webpack/watchpack what to watch, only that --watch flag. Can someone explain this to me?

@alexander-akait
Copy link
Member

Can you provide structure of your project?

@Philipp91
Copy link
Author

Philipp91 commented Jan 4, 2021

See here. I can additionally provide my own setup, but it would take quite a while to strip it down to something that can be posted on GitHub.

@alexander-akait
Copy link
Member

@Philipp91 Yep, please try to provide, and I will investigate this problem, I think something wrong in plugins/loaders/webpack-dev-server, because we are warning /mnt/ and it should not happens

@Philipp91
Copy link
Author

# Use WSL 1
cd /mnt/c/Users/....
mkdir watchpack-reproduce
cd watchpack-reproduce
npm init -y && npm install webpack webpack-cli --save-dev
mkdir src
echo Test > index.html
echo 'console.log(window)' > src/index.js
NODE_ENV=development webpack --watch --watch-options-stdin
# Now the 4 errors posted above appear.

@Philipp91
Copy link
Author

compilation.fileDependencies contains:

[
  '/mnt/c/Users/Philipp/repos/watchpack-reproduce/package.json',
  '/mnt/c/Users/Philipp/repos/watchpack-reproduce/src',
  '/mnt/c/Users/Philipp/repos/watchpack-reproduce/src/index.js',
  '/mnt/c/Users/Philipp/repos/watchpack-reproduce',
  '/mnt/c/Users/Philipp/repos',
  '/mnt/c/Users/Philipp',
  '/mnt/c/Users',
  '/mnt/c',
  '/mnt',
  '/'
]

This may be a new behavior in webpack v5. Is it okay for webpack to tell watchpack to watch all those directories up to the root?

@alexander-akait
Copy link
Member

alexander-akait commented Jan 5, 2021

What is cwd when you run NODE_ENV=development webpack --watch --watch-options-stdin?

@Philipp91
Copy link
Author

It's /mnt/c/Users/Philipp/repos/watchpack-reproduce, I ran it quite exactly as posted above.

@sokra
Copy link
Member

sokra commented Jan 6, 2021

It's normal that these directories are watched. The relevant entry is /mnt/c/Users which is watched because the Users directory could theoretically change to a symlink to some different location. Watchpack always watches to complete directory instead of single files for performance reasons.

So the errors are actually irrelevant for watching these the Users directory. It would probably make sense to ignore them internally until these files are actually watched.

@Philipp91
Copy link
Author

Okay that makes sense. I find it a bit complex to implement due to the series of DirectoryWatcher instances. Now the instance with path="/mnt/c" needs to know that it should suppress all (?) kinds of errors for all (?) files except the /mnt/c/Users subdirectory (which this particular watcher instance doesn't know about, or at least doesn't that it's special).

@sokra
Copy link
Member

sokra commented Feb 7, 2021

which this particular watcher instance doesn't know about

Each instances knows which files are watched on this instance. So there is a /mnt/c instance where only Users is watched. Suppressing the warnings is probably the easy part. More tricky is that someone might start watching hiberfil.sys at a later time. In this case we need to show the warning at this later time.

@Whoops
Copy link

Whoops commented Feb 27, 2021

FWIW I found this thread after running into the same error on Arch Linux. I use pCloud which puts a fuse mount in my home directory and was getting Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/home/whoops/pCloudDrive'. Needless to say, my project isn't in that directory and has no dependency on it. After reading this thread and confirming with some console.logs sure enough WatchPack was trying to lstat that mount point when watching my home directory.

I'm also not sure why it was getting permission denied when it tried, but it was certainly confusing and sent me down some rabbit holes trying to figure out what I misconfigured to make it even try.

@DavidDolyak
Copy link

DavidDolyak commented Mar 6, 2021

What terminal do you use? I have Windows and I am having the same issue with wsl. Try to use cmd instead. It worked for me. Good luck.

@stefanradovanovic
Copy link

I am having the same problem. I am in a process of migrating from Gatsby v2 to v3. As far as i understand, this has something to do with WSL2. I just hope that Gatsby team will not forget this issue.

@jljorgenson18
Copy link

Also running into this. My watch options are only ignoring node_modules so I'm not sure why this would be happening.

@dmondev
Copy link

dmondev commented Mar 31, 2021

Plus one running into the same issue with WSL2 + Windows 10.
I have root mounted as / in WSL, so:

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/c/DumpStack.log.tmp'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/c/hiberfil.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/c/pagefile.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/c/swapfile.sys'

@TravelFiend
Copy link

Plus another, also with WSL2 + Windows 10

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/DumpStack.log.tmp'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/hiberfil.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/pagefile.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/swapfile.sys'

@obipascal
Copy link

Well i also run into the same error. Running windows 10 x64 bit

Watchpack Error (initial scan): Error: UNKNOWN: unknown error, lstat 'C:$360Section'

@alexander-akait
Copy link
Member

C:$360Section interesting, can you provide path on your project?

@obipascal
Copy link

obipascal commented Apr 2, 2021

js

const path = require("path");

// webpack config
module.exports = {
  // partner area main app entry for
  entry: {
    "App.bspa": "./App.bspa.js",
    "App.Admin": "./App.Admin.js",
  },
  output: {
    filename: "[name].min.js",
    path: path.resolve(__dirname, "www/dist"),
  },
  mode: "development",
  watch: true,
  devtool: "eval-source-map",
  watchOptions: {
    ignored: ["**/node_modules"],
    poll: 1000,
    aggregateTimeout: 100,
  },

  module: {
    rules: [
      {
        test: /\.css$/i,
        use: ["style-loader", "css-loader"],
      },
      {
        test: /\.(png|svg|jpg|jpeg|gif)$/i,
        type: "asset/resource",
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/i,
        type: "asset/resource",
      },
    ],
  },
};

@obipascal
Copy link

C:$360Section looks like 360 total security dir

@alexander-akait
Copy link
Member

@obipascal I mean path to the project, i.e. C:\\path\to\project and version of WSL

@obipascal
Copy link

C:\Servers\xampp\htdocs\www\bitmoservice\public

@obipascal
Copy link

image
this is the structure of the project dir

@darvesh
Copy link

darvesh commented Apr 12, 2021

I have this issue on WSL2
path to project: /mnt/c/Users/username/Documents/Projects/gatsby-blog

 ERROR

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/DumpStack.log.tmp'


 ERROR

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/hiberfil.sys'


 ERROR

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/pagefile.sys'


 ERROR

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/swapfile.sys'

Can reproduce like this

gatsby new my-blog-starter https://github.com/gatsbyjs/gatsby-starter-blog
cd my-blog-starter
gatsby develop

@hypotheses
Copy link

I kind of wonder what watchpack is doing with swapfile.sys or through which part.
Not sure if this help or not, but I started hacking react with 'babel' & 'live-server' running manually via command-line. This works fine.

As the course progress, the instructor introduced webpack, and hence, this problem!

@Philipp91
Copy link
Author

So the errors are actually irrelevant for watching these the Users directory. It would probably make sense to ignore them internally until these files are actually watched.

@sokra It seems like you had a particular workaround in mind. It would be great if you could implement and release that. As you say, the errors are harmless. But they don't look like that, and in the face of any (unrelated) issues with Webpack, people will waste lots of time investigating them, and some of the end up here and even take the time to post screenshots and repro-instructions here, which shows how much time they've previously spent on debugging. We should save that time by suppressing the errors.

@alexander-akait
Copy link
Member

/cc @sokra

@lightmyfire17
Copy link

Same here: WSL 2, win 10

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/d/DumpStack.log.tmp'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/d/pagefile.sys'

@aaronendsley
Copy link

aaronendsley commented Apr 16, 2021

Same here: WSL 2, win 10

Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/d/DumpStack.log.tmp'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/d/pagefile.sys'

I get this as well in windows 10 wsl 2, after converting to gatsby 3 in my project

@lightmyfire17
Copy link

Okay, finally fixed it. The problem is with the path as already someone said. Your project should not be located at /mnt/d/... or somewhere on your windows machine. Instead just make sure you have did this:

  1. cd ~ your path here should be like user@user which means /home/user/ in linux
  2. now make git clone/set up project manually

@bebbo
Copy link

bebbo commented Oct 26, 2021

It's normal that these directories are watched. The relevant entry is /mnt/c/Users which is watched because the Users directory could theoretically change to a symlink to some different location. Watchpack always watches to complete directory instead of single files for performance reasons.

The directory /mnt/c/Users is absolutely irrelevant. Maybe relevant is $HOME. And panicing about "the user directory might change during a session, so I better watch it" is pure nonsense.

@pebcakerror
Copy link

After test driving Next.js for the first time today, this issue resulted in long meeting with our corporate security team to make sure some bad actor in the dependency chain didn't just steal a bunch of information.

To take the liberty to go outside the scope like this feels like a trust violation. This wasn't installed as a global npm module. Local should stay local. Or am I misunderstanding Node's ecosystem?

$ npm run dev

> dev
> next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/DumpStack.log.tmp'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/hiberfil.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/pagefile.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/swapfile.sys'
event - compiled successfully in 14.8s (159 modules)
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/DumpStack.log.tmp'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/pagefile.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/hiberfil.sys'
Watchpack Error (initial scan): Error: EACCES: permission denied, lstat '/mnt/c/swapfile.sys'
Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry

@geraldoam
Copy link

Same problem. Win 11 and WSL2.

@sokra
Copy link
Member

sokra commented Nov 24, 2021

I'll fix the unnecessary warnings, but that won't fix the watching.

Watching in /mnt/c won't work correctly. It's the windows filesystem mounted in linux. While that being super slower, its watching is also only partially implemented. Please don't try that. Put your project outside of /mnt/c. That's faster and more reliable. (Note that modifying files from windows still won't trigger a watch event)

See also this (long) issue: microsoft/WSL#4739

@geraldoam
Copy link

geraldoam commented Nov 24, 2021

Hey guys. Try:

  • Delete your node_modules.
  • Move your project folder to /home/$USER and install node_modules again. It's worked for me.
# delete node_modules
mv (your_project_folder) /home/$USER
cd /home/$USER/(your_project_folder)
yarn install
yarn start # or yarn dev

If don't work install webpack global package and try again.
I'm using Windows 11 with WSL 2.

@dbooyah93
Copy link

dbooyah93 commented Nov 26, 2021 via email

@pedrodahmer
Copy link

Okay, finally fixed it. The problem is with the path as already someone said. Your project should not be located at /mnt/d/... or somewhere on your windows machine. Instead just make sure you have did this:

1. `cd ~` your path here should be like `user@user` which means `/home/user/` in linux

2. now make git clone/set up project manually

This one fixed it for me! Thank you!

@TheUniquePaulSmith
Copy link

So, I ran into this issue to because I was dumb and accidently ran npm next dev in a command prompt on windows and I think it messed up my webpack watcher?

As others have mentioned, With WSL2 when running a Git repo + node_modules on a windows filesystem but compiling within the /mnt/c/* path with WSL2 is notoriously slow! Because windows filesystem access through WSL2 is not performant.

Microsoft calls this out and recommends people run WSL1 if you are trying that approach -> Source

For me, I just want to code in VSCode, and use all the useful kernel level tools and tooling in linux eco-system, including nodejs, apt-get tools, etc.

Some people have problems moving the project to internal system in linux because it's less accessible and off the NTFS file system (for permissions).

For me personally a good hybrid solution was to move the entire project inside the linux home directory. Then inside WSL2 prompt at the path of the project you can run explorer.exe . which will open a windows explorer to the linux path.
The path is a hidden file share that exists with WSL2.

I then took that UNC folder path and made it a shortcut where the initial project used to exist on "c:\source\projectA (/mnt/c/source/projectA) so that I can still open and develop in VSCode.

This solution only works well if you're not dependent on launch.json with VSCode to windows executables for your project.
I debug and launch within WSL2 but lint, and code in VSCode

@adamisse
Copy link

Okay, finally fixed it. The problem is with the path as already someone said. Your project should not be located at /mnt/d/... or somewhere on your windows machine. Instead just make sure you have did this:

  1. cd ~ your path here should be like user@user which means /home/user/ in linux
  2. now make git clone/set up project manually

It worked for me! Tnks bro 👍🏻

@mateustormin
Copy link

Nothing here worked for me, my source is within wsl2 filesystem (/home//git/ but still it tries to scan the entire filesystem including /mnt/, /proc/

.... Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/proc/1/fd' Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/proc/1/fdinfo' Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/proc/1/map_files' .... Watchpack Error (watcher): Error: EACCES: permission denied, watch '/mnt/c/Windows/SysWOW64/sru' Watchpack Error (watcher): Error: EACCES: permission denied, watch '/mnt/c/Windows/appcompat/Programs' Watchpack Error (watcher): Error: EACCES: permission denied, watch '/mnt/c/Windows/security/audit' Watchpack Error (watcher): Error: EACCES: permission denied, watch '/mnt/c/Windows/security/cap' Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/cache/apt/archives/partial' ....

the list goes on, I think it extends every file in wsl2 (including windows filesystem in /mnt/)
At first I just moved the project dir from windows to wsl2 but then I tried to remove everything, git clone and npm install again but without success.

Are we close to figure this out?

@bebbo
Copy link

bebbo commented May 5, 2022

Are we close to figure this out?

rather web folders are also scanned, than this is restricted to the working folder...

@BrunoYamazaki
Copy link

Okay, finally fixed it. The problem is with the path as already someone said. Your project should not be located at /mnt/d/... or somewhere on your windows machine. Instead just make sure you have did this:

1. `cd ~` your path here should be like `user@user` which means `/home/user/` in linux

2. now make git clone/set up project manually

This one fixed it for me! Thank you!

work for me too

@gnubyte
Copy link

gnubyte commented Jul 31, 2022

If anyone else encounters this like I did on Windows with WSL, I glanced over watchpack's code tonight and didn't see anything fishy as of 7-30-2022. What I really worry about is Watchpack recursively iterating my drive and sending its results elsewhere. As would anyone when they start to see the code getting access denied to directories that aren't exactly what you asked it to watch.

Its a relatively simple codebase and if you're worried, I recommend taking a look at it or watchpacks' own files on your system.

@FredLackeyOfficial
Copy link

FredLackeyOfficial commented Aug 27, 2022

Suggesting folks move their code from /mnt/... to ~ is complete nonsense. The primary OS in all of these examples is Windows and the rules we use must should put Windows first. Especially when virtually every tool use (VSCode, etc.) doesn't care that you are running [essentially] an emulator on top of the OS. Using a mountpoint under /mnt to access a device outside of Linux is the proper way of connecting to C:\ or any other drive. Guess with the logic above, developers are expected to never use any other drive besides C?

The same holds true for anyone trying to excuse the bad behavior of Watchpack / Webpack. Creating a file watcher at any parent folder to your project means you are allowing the component to examine, and possibly react to, file changes in completely unrelated folder structures. Even if we want to believe that no harm will come to those other files and folders, at a minimum this means that additional processing power is unnecessarily being used watching countless files that are not relevant to our project.

On my Linux and Mac boxes I use ~/Source as it is natural and expected for those operating systems. While on Windows I use C:\_ as my source folder. This decreases the chance of running into a Windows path length limitation as it is not always possible to enable long paths. Any app relying on WSL is just that; an application. This includes an instance of nNix running within WSL. There's no way I'm going to bury data in any appllication or application-specific location

The bottom line is that a project folder is created to ensure only the files in that structure are ever touched. No utility has any business touching, watching, or examining any other folder or file on the system. Doing so is unethical and, at a minimum, incredibly lazy. Stop excusing bad behavior.

@sukretniy
Copy link

sukretniy commented Dec 25, 2022

I'm trying to create next.js app with

npx create-next-app@latest

on my hosting provider. After that I run

npm run dev

The app seems to be started, but I get following errors:

testh3@vs828:/var/www/testh3/test.gsmcounters.com$ npm run dev

[email protected] dev next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000
Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www'
Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www'
Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www'
Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www'
Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www'
Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www'
Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www'
Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www'
event - compiled client and server successfully in 1967 ms (165 modules)
wait - compiling...
event - compiled successfully in 38 ms (132 modules) wait - compiling...
event - compiled successfully in 18 ms (33 modules)
[webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies
wait - compiling / (client and server)...
event - compiled client and server successfully in 1084 ms (194 modules)
[webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies

How can I change that behaviour to fix error?

@vitormarkis
Copy link

I'm trying to create next.js app with

npx create-next-app@latest

on my hosting provider. After that I run

npm run dev

The app seems to be started, but I get following errors:

testh3@vs828:/var/www/testh3/test.gsmcounters.com$ npm run dev

[email protected] dev next dev

ready - started server on 0.0.0.0:3000, url: http://localhost:3000 Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www' Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www' Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www' Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www' Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www' Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www' Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www' Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www' event - compiled client and server successfully in 1967 ms (165 modules) wait - compiling... event - compiled successfully in 38 ms (132 modules) wait - compiling... event - compiled successfully in 18 ms (33 modules) [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies wait - compiling / (client and server)... event - compiled client and server successfully in 1084 ms (194 modules) [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies

How can I change that behaviour to fix error?

same here, did you managed to fix it?

@dbooyah93
Copy link

I'm trying to create next.js app with

npx create-next-app@latest

on my hosting provider. After that I run

npm run dev

The app seems to be started, but I get following errors:
testh3@vs828:/var/www/testh3/test.gsmcounters.com$ npm run dev
[email protected] dev next dev
ready - started server on 0.0.0.0:3000, url: http://localhost:3000 Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www' Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www' Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www' Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www' Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www' Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www' Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www' Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/var/ www' event - compiled client and server successfully in 1967 ms (165 modules) wait - compiling... event - compiled successfully in 38 ms (132 modules) wait - compiling... event - compiled successfully in 18 ms (33 modules) [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies wait - compiling / (client and server)... event - compiled client and server successfully in 1084 ms (194 modules) [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies [webpack.cache.PackFileCacheStrategy] Caching failed for pack: Error: Unable to snapshot resolve dependencies
How can I change that behaviour to fix error?

same here, did you managed to fix it?

I think you might need a new sub. Check that the node version you have matches the dependency version.

It's so specific that it's hard to tell with just this. Create a new thread with all the details of your local server

@liujingbreak
Copy link

I wrote a Hack plugin to workaround this issue:

import {Compiler} from 'webpack';
...
apply(compiler: Compiler) {
const lookupSet = new Set<string>(['/', '/data', '/data/data']; // Those EACCES directories
compiler.hooks.done.tap('TermuxIssueResolve', stats => {
      for (const item of stats.compilation.fileDependencies) {
        if (lookupSet.has(item)) {
          // eslint-disable-next-line no-console
          console.log('[TermuxIssueWebpackPlugin] remove unaccessible fileDependency', item);
          stats.compilation.fileDependencies.delete(item);
        }
      }
    });
}
...

@thepian
Copy link

thepian commented Apr 26, 2023

Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/Volumes/Projects/.fseventsd'

@subhasish-smiles
Copy link

This is still happening in latest next js 13.4

@essenmitsosse
Copy link

Just for completeness' sake, since most people seem to have this problem on Windows, I got it on Mac.

System: MacOS Ventura Version 13.4.1
Node: v18.16.0

Watchpack Error (watcher): Error: EACCES: permission denied, watch '/Volumes/code/.fseventsd'
Watchpack Error (initial scan): Error: EACCES: permission denied, scandir '/Volumes/code/.fseventsd'

The project(s) are in a /Volumes/code/PROJECT_FOLDER.

@essenmitsosse
Copy link

Interestingly enough: The problem doesn't occur when I copy the project to my main volume. So since many WSL users have it, might it be related to running on a different volume then the user?

@Viranchee
Copy link

Hi @essenmitsosse I'm using a different volume too on MacOS, /Volumes/code and I get the same error as you.
I haven't tried out putting it on my main volume yet, but thanks for the heads up!

@mateustormin
Copy link

For those who have the same error on an angular project, might be worth loking at this answer. it fixed my project that has been given me headaches since the start of this post

@irisma00
Copy link

irisma00 commented Aug 7, 2024

I wrote a Hack plugin to workaround this issue:

import {Compiler} from 'webpack';
...
apply(compiler: Compiler) {
const lookupSet = new Set<string>(['/', '/data', '/data/data']; // Those EACCES directories
compiler.hooks.done.tap('TermuxIssueResolve', stats => {
      for (const item of stats.compilation.fileDependencies) {
        if (lookupSet.has(item)) {
          // eslint-disable-next-line no-console
          console.log('[TermuxIssueWebpackPlugin] remove unaccessible fileDependency', item);
          stats.compilation.fileDependencies.delete(item);
        }
      }
    });
}
...

Where did you put this code tho? Thanks

@scourgetheone
Copy link

scourgetheone commented Aug 20, 2024

Hi @irisma00! you can add this code directly in the "plugins" attribute of your webpack.config.js like so:

// Example webpack.config.js file
module.exports = {
    entry: {
        app: "./src/index.js",
    },
...
    plugins: [
        {
            apply: function(compiler) {
                const lookupSet = new Set(["/", "/data", "/data/data"]) // Those EACCES directories
                compiler.hooks.done.tap("WatchpackBugWorkaroundPlugin", (stats) => {
                    for (const item of stats.compilation.fileDependencies) {
                        if (lookupSet.has(item)) {
                            console.log(
                                "[WatchpackBugWorkaroundPlugin] remove inaccessible fileDependency",
                                item
                            )
                            stats.compilation.fileDependencies.delete(item)
                        }
                    }
                })
            }
        },
    ],

Replace the file paths in const lookupSet = new Set(["/", "/data", "/data/data"]) with the actual file paths where you see the EACCES: permission denied..." logs when you run webpack/webpack-dev-server. So for example, if you see Watchpack Error (watcher): Error: EACCES: permission denied, watch '/var/www' in the output of your webpack command, then add "/var/www" to the lookupSet of the custom plugin we made above.

I don't understand Webpack enough to judge if @liujingbreak's code does the job, perhaps those who try out this hack can test it out together.

Update: I tested out the code, and it works: it removes the chosen directories from being watched. I tested that it works as intended using 2 ways. First, I deliberately added the path to a source file in my project in the lookupSet, ran webpack-dev-server, made some changes in said file, and saw that the dev server did not recompile/reload at all! The second way I was able to verify, is by running the following command to get the list of files being watched by webpack using strace (note: this command works only on Linux):

strace -fe inotify_add_watch ./node_modules/.bin/webpack-dev-server --mode development 2>&1 | sed -u "s#$(pwd)#.#g" | grep -o --line-buffered '".*"' | tr -d '"'

Source: https://hassansin.github.io/Finding-out-Which-Files-Are-Watched-by-Webpack-Using-Strace

I also tweaked our hack plugin abit to only include files from my project's UI source code folder:

apply: function (compiler) {
    const sourceCodeDirectory = path.resolve(__dirname, "src")
    compiler.hooks.done.tap(
        "WatchpackBugWorkaroundPlugin",
        (stats) => {
            for (const item of stats.compilation.fileDependencies) {
                if (!item.includes(sourceCodeDirectory)) {
                    stats.compilation.fileDependencies.delete(item)

So this hack plugin works as intended! Now I no longer need to worry about webpack watching unrelated files outside my project folder whichexausts the system's fs.inotify.max_user_watches limit thus preventing recompile/live-reload when it's actually needed like my source code changes.

P.s: I have this issue on both Ubuntu server 22.04 and Termux on Android. The testing of the hack plugin was only done on Termux on Android.

@CumpsD
Copy link

CumpsD commented Sep 26, 2024

I have the same on Linux, with Docosaurus, which uses webpack underneath. My project is in /home/cumpsd/...., a regular folder, but when I start it I get the following:

Watchpack Error (initial scan): Error: ENODEV: no such device, lstat '/efi'

It makes no sense why this would try to touch /efi

I'm trying to find out how I can apply the above Hack plugin, but since webpack is hidden from me in this case, it's a whole lot harder

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests