-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bundling fails without read permission to parent directories #938
Comments
I did notice something similar for output file paths. Here's a contrived example for demonstration purposes:
Side note... not crazy about the need for the extra typing needed to disable the verbose output:
Although I'd prefer the way esbuild used to work with UNIX-style "silent by default except for errors", might you consider having |
@kzc Don't use
|
@heyheyhello I prefaced my comment with:
|
Yeah and your contrived example is great to show the |
It was a side note based on the previous command. Here's a simpler example: Compare the length of this command:
to this one:
Once anyone has used esbuild once they never need to see the verbose output again and will have to type |
I think the use case you're imagining is very different than a lot of developers... Personally I want to see the build size everytime I build. When esbuild used to not show it the first thing I'd do after was an |
Thanks for reporting this issue. I'm aware of the issue and it's come up once before here: #803 (comment). I gave fixing it a quick try then but I was unable to reproduce the issue myself (didn't try too hard at the time) and gave up. Even your repro instructions fail to cause the issue for me. I can give it another shot though. The underlying reason is that esbuild makes heavy use of caching to avoid huge performance issues with node's path resolution algorithm. The algorithm is inherently inefficient because it involves making potentially hundreds of file system queries to resolve each individual import path (check all implicit file extensions * check My implementation caches file system syscalls in the resolver to try to make this as efficient as possible. The cache in the resolver currently works by ensuring the parent directory is cached before caching a child directory, but that doesn't work if a parent directory is off-limits. Without investigating this myself first, I'm not totally sure what would need to change about the caching strategy to fix this problem correctly. But I agree that it should be fixed. |
Cool, thanks for the explanation! @ Repro: For context, the commands above were run on Ubuntu 20.10, several times with the unreadable directory at different levels above the root, and always caused the issue for me. |
repro:
|
TIL...
|
I can reproduce the issue if I use $ mkdir -p some/dir
$ cd some/dir
$ echo {} > package.json
$ npm i esbuild webpack webpack-cli parcel@next rollup
$ echo 'import "./1.mjs"' > 0.mjs
$ echo 'console.log("works")' > 1.mjs
$ node 0.mjs
works
$ chmod 000 ..
$ node_modules/.bin/esbuild --bundle 0.mjs
> error: Cannot read directory "../..": permission denied
> error: Cannot read directory ".": permission denied
> error: Could not resolve "0.mjs"
3 errors
$ node 0.mjs
internal/bootstrap/switches/does_own_process_state.js:129
cachedCwd = rawMethods.cwd();
^
Error: EACCES: permission denied, uv_cwd
at process.wrappedCwd [as cwd] (internal/bootstrap/switches/does_own_process_state.js:129:28)
at Object.resolve (path.js:978:47)
at resolveMainPath (internal/modules/run_main.js:12:40)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:66:24)
at internal/main/run_main_module.js:17:47 {
errno: -13,
code: 'EACCES',
syscall: 'uv_cwd'
}
$ node_modules/.bin/webpack ./0.mjs
internal/bootstrap/switches/does_own_process_state.js:129
cachedCwd = rawMethods.cwd();
^
Error: EACCES: permission denied, uv_cwd
at process.wrappedCwd [as cwd] (internal/bootstrap/switches/does_own_process_state.js:129:28)
at Object.resolve (path.js:978:47)
at resolveMainPath (internal/modules/run_main.js:12:40)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:66:24)
at internal/main/run_main_module.js:17:47 {
errno: -13,
code: 'EACCES',
syscall: 'uv_cwd'
}
$ node_modules/.bin/parcel build 0.mjs
internal/bootstrap/switches/does_own_process_state.js:129
cachedCwd = rawMethods.cwd();
^
Error: EACCES: permission denied, uv_cwd
at process.wrappedCwd [as cwd] (internal/bootstrap/switches/does_own_process_state.js:129:28)
at Object.resolve (path.js:978:47)
at resolveMainPath (internal/modules/run_main.js:12:40)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:66:24)
at internal/main/run_main_module.js:17:47 {
errno: -13,
code: 'EACCES',
syscall: 'uv_cwd'
}
$ node_modules/.bin/rollup 0.mjs
internal/bootstrap/switches/does_own_process_state.js:129
cachedCwd = rawMethods.cwd();
^
Error: EACCES: permission denied, uv_cwd
at process.wrappedCwd [as cwd] (internal/bootstrap/switches/does_own_process_state.js:129:28)
at Object.resolve (path.js:978:47)
at resolveMainPath (internal/modules/run_main.js:12:40)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:66:24)
at internal/main/run_main_module.js:17:47 {
errno: -13,
code: 'EACCES',
syscall: 'uv_cwd'
} So it's not clear what esbuild's behavior should be in that case. It sort of seems like it's fine for it to not work in that scenario of node itself doesn't even work. Note that this is on macOS. |
Ha, I just tried the exact same steps, but with This is fun, I'm learning some things about permissions (no expert here either). |
TIL the
|
Thanks for all the help. Now I finally understand the problem. I think an appropriate fix should be to just treat this directory as empty, since node seems to let you still import packages declared in the parent directory of the inaccessible directory. Treating it as empty means esbuild will simply pass through it on its search for packages. Working on a fix now. |
@kzc regarding the tangent about the new summary logging after builds: I understand the desire to have clean terminal output. Here is my rationale for the change, from the most recent release notes:
Some examples of people encountering this problem in the wild:
I'm turning it on by default because I believe that doing this improves the UX in the majority of cases, and it's easy to turn off if you don't want it. I expect most uses of esbuild to be done through code (npm scripts or API calls) instead of manually-typed commands, in which case adding a parameter to disable it is not a problem. And I expect that in the majority of cases printing the summary for manually-typed commands is the right thing to do, in which case adding a parameter to disable it is the minority use case. I think adding Given these concerns, I think a better way would be to support an environment variable such as |
@evanw thanks for the explanation and consideration. And thanks for esbuild and the long hours you put into it each week making it rock solid and thoughtfully responding to everyone. I wonder how you find the time. No need to add an environment variable on my account. With the env var you'd have the opposite problem - remembering to unset it on the rare occasions you'd actually like to see a warning. As I mentioned, it's just a minor annoyance. For command line usage I can create an alias for Just curious... Regarding changing the absolute paths of inputs and outputs to relative paths from the current working directory - is that intentional and also related to the node resolve algorithm? |
It's intentional but not related to path resolution. Paths are always resolved to absolute paths internally but are pretty-printed as relative paths in error messages. This is both because relative paths are usually shorter than absolute paths and because this makes error messages deterministic across platforms instead of encoding platform-specific differences such as the user's home directory and/or |
@evanw this fix seems not including some cross build problem (Windows), somehow Reproduce it in a Windows10x64 VM: logs (I update the code to output $ esbuild --log-level=verbose test.js
X [ERROR] Cannot read directory "..": Access is denied. , error code: 5
♦ [VERBOSE] Resolving import "./test.js" in directory "B:\\esbuild_test\\parent_not_readable\\myproject" of type "entry-point"
Read 4 entries for directory "B:\\"
Read 1 entry for directory "B:\\esbuild_test"
Failed to read directory "B:\\esbuild_test\\parent_not_readable": open B:\esbuild_test\parent_not_readable: Access is denied.
Failed to read directory "B:\\esbuild_test\\parent_not_readable"
Failed to read directory "B:\\esbuild_test\\parent_not_readable\\myproject"
Failed to read directory "B:\\esbuild_test\\parent_not_readable\\myproject"
Failed to read directory "B:\\esbuild_test\\parent_not_readable\\myproject"
Attempting to load "B:\\esbuild_test\\parent_not_readable\\myproject\\test.js" as a file
Checking for file "test.js"
Found file "test.js"
Failed to read directory "B:\\esbuild_test\\parent_not_readable\\myproject"
Primary path is "B:\\esbuild_test\\parent_not_readable\\myproject\\test.js" in namespace "file"
1 error A locally built 0.18.20 version in a Windows10 VM can work in that VM, but a same version installed by npm cannot. |
Hi, I am trying to use esbuild on an Ubuntu VPS where my
$HOME
directory is/usr/home/<USER>
, but I don't have read permission to the parent folder/usr/home
.This causes bundling to fail with
Cannot read directory ... permission denied
The error can be reproduced on any machine by mimicking the permissions layout:
Output:
From my (ignorant) viewpoint it seems unnecessary to read anything above the package root when resolving node modules, so I thought esbuild could possibly prevent tripping up in this situation. (E.g. Webpack bundles without errors in the same situation.)
The text was updated successfully, but these errors were encountered: