Support yarn/npm link'ed packages by default #5654
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains a simple update to the dev/prod webpack configurations that enables
yarn link
andnpm link
to work out of the box withreact-scripts
.Background
Webpack provides a
resolve.symlinks
configuration option, and the documentation states:…and it does. A basic failing use case is:
# /some/local/directory/foo/package.json
# /some/local/directory/foo/index.js
If I run
yarn link foo
inside areact-scripts
project, theresolve.symlinks
option will tellwebpack
to resolve./node_modules/foo -> /some/local/directory/foo
with Node module resolution applied to all therequire(...)
s therein. In particular, this means that inside this symlinked module,require('react')
will do one of two things:/some/local/directory/foo/node_modules/react
instead of./node_modules/react
)[yarn|npm] install
in/some/local/directory/foo
yet.Clearly neither of these is desirable—the typical use case for
yarn link
is to shim an in-development library into another project exactly as if it had been installed viayarn
, except possibly with local modifications. I have even worked with teams that deploy from codebases withyarn link
'ed dependencies.Rationale
I'm proposing this change because I think supporting
yarn link
andnpm link
is a relatively common use case (see #3547 and the various associated issues), and that the use cases in which we would want to resolve symlinks to their actual locations are far more advanced than the use cases in which we wouldn't. So this seems to meet the needs of the pre-ejection CRA target audience better than the defaultwebpack
symlink resolution behavior.