Skip to content

Support yarn/npm link'ed packages by default #5654

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

stristr
Copy link

@stristr stristr commented Oct 31, 2018

This PR contains a simple update to the dev/prod webpack configurations that enables yarn link and npm link to work out of the box with react-scripts.

Background

Webpack provides a resolve.symlinks configuration option, and the documentation states:

this may cause module resolution to fail when using tools that symlink packages (like npm link)

…and it does. A basic failing use case is:

# /some/local/directory/foo/package.json

{
  "name": "foo",
  "main": "index.js",
  "dependencies": {"react" : "..."},
  ...
}

# /some/local/directory/foo/index.js

const react = require('react');
// ...

If I run yarn link foo inside a react-scripts project, the resolve.symlinks option will tell webpack to resolve ./node_modules/foo -> /some/local/directory/foo with Node module resolution applied to all the require(...)s therein. In particular, this means that inside this symlinked module, require('react') will do one of two things:

  1. Resolve to whatever version has been installed locally (e.g. /some/local/directory/foo/node_modules/react instead of ./node_modules/react)
  2. Fail to resolve at all if I haven't run [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 via yarn, except possibly with local modifications. I have even worked with teams that deploy from codebases with yarn link'ed dependencies.

Rationale

I'm proposing this change because I think supporting yarn link and npm 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 default webpack symlink resolution behavior.

@stristr
Copy link
Author

stristr commented Oct 31, 2018

Prior art: #3695

@stale
Copy link

stale bot commented Nov 30, 2018

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Nov 30, 2018
@stristr
Copy link
Author

stristr commented Nov 30, 2018

Keep alive!

@stale stale bot removed the stale label Nov 30, 2018
@stale
Copy link

stale bot commented Dec 31, 2018

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

@stale stale bot added the stale label Dec 31, 2018
@stristr
Copy link
Author

stristr commented Jan 1, 2019

Keep alive!

@yhnavein
Copy link

@stristr Can you check if other approach from my PR (#6207) works for your case?

@stristr
Copy link
Author

stristr commented Jan 18, 2019

Closing in favor of #6207.

@stristr stristr closed this Jan 18, 2019
@lock lock bot locked and limited conversation to collaborators Jan 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants