Resolve symlinks using Node resolution mechanism
See original GitHub issueCopying 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.
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:
- Created 6 years ago
- Reactions:6
- Comments:16 (8 by maintainers)
Top GitHub Comments
I think the correct fix would be to:
npm link
really wantIs 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?