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.

Resolve symlinks using Node resolution mechanism

See original GitHub issue

Copying my comment from #1107 since that issue is pretty crowded and I want it to be here instead.


Having read some discussions in https://github.com/nodejs/node/pull/6537 and https://github.com/isaacs/node6-module-system-change I think we’re actually already being inconsistent in how we handle symlinks.

Let’s forget about the issue about compiling source code for a second. I feel like that can be solved by https://github.com/facebookincubator/create-react-app/issues/1333 and thus is not the most important one here.

The important part here is that the resolution should match Node algorithm so that our webpack setup matches our test setup. I thought that was the case, but I was wrong.

Consider this structure:

my-comp
  index.js // already compiled
  package.json // react is a peer dependency

my-app
  node_modules
    my-comp // symlink to my-comp folder

It turns out that if my-comp doesn’t declare a dependency on react, it can find React in the browser builds but not in tests.

screen shot 2018-01-21 at 12 25 54 screen shot 2018-01-21 at 12 26 06

We introduced this regression in https://github.com/facebookincubator/create-react-app/pull/1359.

We probably missed it because if my-comp does explicitly depend on React (e.g. as a devDependency), the test passes (and in the browser we just get two Reacts).

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:6
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
gaearoncommented, Jan 21, 2018

I think the correct fix would be to:

  • Have the webpack build respect Node resolution and fail in this case
  • Add an opt-in to Node “preserve symlinks” behavior which seems to be what people using npm link really want
4reactions
pietmichalcommented, Mar 7, 2019

Is there a scenario where someone would prefer having dependencies read from linked node_modules instead from CRA-based project’s node_modules? Modifying webpack.config.js to have { resolve: { symlinks: false } } fixes the “two react” problem.

If there is no scenario, then maybe CRA should have the value, from above, hardcoded?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolve | webpack
Resolve. These options change how modules are resolved. Webpack provides reasonable defaults, but it is possible to change the resolving in detail.
Read more >
npm-link
When creating tarballs for npm publish , the linked packages are "snapshotted" to their current state by resolving the symbolic links, if they...
Read more >
Node JS resolve paths with symlinks - Stack Overflow
I am retrieving a list of items in a directory with fs.readdirSync(somePath) . In this directory there are subdirectories or links to other ......
Read more >
Command-line API | Node.js v19.3.0 Documentation
--preserve-symlinks #. Added in: v6.3.0. Instructs the module loader to preserve symbolic links when resolving and caching modules. By default, when Node.js ...
Read more >
Symbolic link - Wikipedia
In computing, a symbolic link is a file whose purpose is to point to a file or directory (called the "target") by specifying...
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