Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Merge requests
  • !5654

Support yarn/npm link'ed packages by default

  • Review changes

  • Download
  • Email patches
  • Plain diff
Closed Administrator requested to merge github/fork/stristr/master into master Oct 31, 2018
  • Overview 7
  • Commits 1
  • Pipelines 0
  • Changes 2

Created by: stristr

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.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/stristr/master