preserveSymlinks doesn't work properly from root package
See original GitHub issueConsider a library lib
with the following file structure:
root
- common
- node_modules
- resolve
- buffer
- mylib
- node_modules
- buffer -> ../../common/node_modules/buffer
- src
- index.js
In other words, a dependency exists from the root library to buffer
which is symlinked into a separate folder (similar to how pnpm works).
In this case, resolve
doesn’t seem to be mapping the symlinked paths to real paths properly.
Repro Steps
- Create the above example with mkdir/ln -s
- cd into root/mylib/src, run node.exe
- import
resolve
and observe thatresolve('buffer/')
returns the symlinked path (root/mylib/node_modules/buffer
) instead of the real path (root/common/node_modules/buffer
).
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (4 by maintainers)
Top Results From Across the Web
TSConfig Reference - Docs on every TSConfig option
Offers a way to configure the root directory for where declaration files are emitted. example ├── index.ts ├── package.json └── tsconfig.json.
Read more >What are Docker COPY's rules about symlinks / how can I ...
This works if you try to copy the entire directory as a unit, rather than trying to copy the files in the directory:...
Read more >pnpm/pnpm - Gitter
Hey community. I can't install any packages with pnpm , the command exits with error but no message shows up in the prompt....
Read more >Configuring Jest
The root directory that Jest should scan for tests and modules within. If you put your Jest config inside your package.json and want...
Read more >Runner cache does not preserve symlink mtime - GitLab.org
Restoring cache Successfully extracted cache Running before_script and script $ ls -l node_modules/.bin/nopt || true lrwxrwxrwx. 1 root root ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
See #197.
Hmmm… If the aim is to mimic the return value of the
require.resolve()
API from NodeJS, then I agree it should be changed. The fix is pretty easy; callfs.realpathSync()
on the return value.Symlinks are used heavily in installations done by PNPM and also Rush, though. By now most tools support that, and rely on the
resolve
package somehow in their solution. Thus perhaps the explanation is that most callers don’t care whether the result is normalized or not. For example, here and here is code that works fine when traversing symlinks, because the next step is to load the file, and it doesn’t really matter whether that path is normalized or not.If we fix this “bug”, it might be a good idea to release it as SemVer MINOR (or MAJOR?), since it could theoretically break tools that might have relied on the current behavior somehow.