You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When bundling code that imports a dependency through nested symlinked directories, esbuild fails with Could not read from file. However, running the same code using node works.
Background: I'm looking to use esbuild for projects in a monorepo that has some fanciness with symlinks for various legacy reasons. The project structure looks like:
Putting aside debates about whether this structure is a Good Idea:tm: or not (there's definitely part of me that says this symlinking example is a little crazy), it seems like this might be an edge-case in esbuild. Both node and Webpack resolve the symlinks without issue.
$ node in.js # Code works when run with node
ok { foo: 123, qux: 321 }
$ ./node_modules/.bin/esbuild in.js --bundle
✘ [ERROR] Could not read from file: /private/tmp/mvce/baz/foo/index.js
in.js:3:20:
3 │ const foo = require('./baz/bar/foo');
╵ ~~~~~~~~~~~~~~~
1 error
FWIW, the --preserve-symlinks behavior is as expected:
$ ./node_modules/.bin/esbuild in.js --bundle --preserve-symlinks
✘ [ERROR] Could not resolve "../qux"
baz/bar/foo/index.js:3:20:
3 │ const qux = require('../qux');
╵ ~~~~~~~~
1 error
$ node --preserve-symlinks in.js
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '../qux'
Require stack:
- /private/tmp/mvce/baz/bar/foo/index.js
- /private/tmp/mvce/in.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/private/tmp/mvce/baz/bar/foo/index.js:3:13)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
code: 'MODULE_NOT_FOUND',
requireStack: [
'/private/tmp/mvce/baz/bar/foo/index.js',
'/private/tmp/mvce/in.js'
]
}
At the moment, I think this is related to the symlink resolution code here. I'm happy to investigate further. However, figured it'd be better to create an issue before going too far.
When bundling code that imports a dependency through nested symlinked directories,
esbuild
fails withCould not read from file
. However, running the same code usingnode
works.Background: I'm looking to use
esbuild
for projects in a monorepo that has some fanciness with symlinks for various legacy reasons. The project structure looks like:If the symlinks were resolved, a project's structure would look something like:
Putting aside debates about whether this structure is a Good Idea:tm: or not (there's definitely part of me that says this symlinking example is a little crazy), it seems like this might be an edge-case in
esbuild
. Bothnode
and Webpack resolve the symlinks without issue.MVCE
Download: symlink-mvce.zip
Versions
Output
FWIW, the
--preserve-symlinks
behavior is as expected:Related
The text was updated successfully, but these errors were encountered: