Skip to content

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

Closed
stristr wants to merge 1 commit into
react:masterfrom
stristr:master
Closed

Support yarn/npm link'ed packages by default#5654
stristr wants to merge 1 commit into
react:masterfrom
stristr:master

Conversation

@stristr

Copy link
Copy Markdown

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.symlinksconfiguration 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
Copy Markdown
Author

Prior art: #3695

@stale

staleBot commented Nov 30, 2018

Copy link
Copy Markdown

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.

@stalestaleBot added the stale label Nov 30, 2018
@stristr

Copy link
Copy Markdown
Author

Keep alive!

@stalestaleBot removed the stale label Nov 30, 2018
@stale

staleBot commented Dec 31, 2018

Copy link
Copy Markdown

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.

@stalestaleBot added the stale label Dec 31, 2018
@stristr

Copy link
Copy Markdown
Author

Keep alive!

@yhnavein

Copy link
Copy Markdown

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

@stristr

Copy link
Copy Markdown
Author

Closing in favor of #6207.

@stristrstristr closed this Jan 18, 2019
@locklockBot locked and limited conversation to collaborators Jan 23, 2019
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@stristr@yhnavein@facebook-github-bot