question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

preserveSymlinks doesn't work properly from root package

See original GitHub issue

Consider 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

  1. Create the above example with mkdir/ln -s
  2. cd into root/mylib/src, run node.exe
  3. import resolve and observe that resolve('buffer/') returns the symlinked path (root/mylib/node_modules/buffer) instead of the real path (root/common/node_modules/buffer).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
ljharbcommented, Jul 30, 2019

See #197.

2reactions
octogonzcommented, Jul 30, 2019

in the “preserve symlinks” case - which node used to do by default - resolve is correct.

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; call fs.realpathSync() on the return value.

I suspect the reasons this hasn’t been reported before include that resolve’s preserveSymlinks: false behavior is relatively newly added, and also symlinking is done pretty rarely historically.

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found