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
  • !1359

Fix importing npm linked libraries

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/AsaAyers/npm-link into master Jan 07, 2017
  • Overview 18
  • Commits 3
  • Pipelines 0
  • Changes 2

Created by: AsaAyers

Looking through the npm link issues, I see two use cases:

  1. (#1356) using npm link to test react-scripts
  2. using npm link for libraries your app depends on.

This PR solves the 2nd case. Webpack's official solution for npm link is to add your project's node_modules to resolve.fallback on the config.

To verify the issue and fix create a small library to link:

cd /tmp
git clone https://gist.github.com/f40e1bad454626691097b4cc4651208c.git link-example
cd link-example
npm link
# to clean this up when you're done, return and run `npm unlink`

Then create your app and link the library.

create-react-app my-app
cd my-app
npm link link-example
echo 'import "link-example"' > src/index.js
npm run build

With the current published version, the build will fail:

> [email protected] build /tmp/my-app
> react-scripts build

Creating an optimized production build...
Failed to compile.

Module not found: Error: Cannot resolve module 'react' in /tmp/link-example

Even though my-app imported ./node_modules/link-example/index.js, the symlink causes webpack to treat it like you required /tmp/link-example/index.js.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/AsaAyers/npm-link