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

Only honor relative NODE_PATH

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Administrator requested to merge github/fork/gaearon/only-honor-relative-node-path into master Dec 07, 2016
  • Overview 5
  • Commits 1
  • Pipelines 0
  • Changes 1

Created by: gaearon

We used to honor NODE_PATH because it provides a relatively convenient way to allow absolute imports for people who need them: NODE_PATH=src npm start.

However this backfired with #1023 (closed) and #815 (closed). The best analysis is in https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421.

Sometimes, a module (which may be inside a dependency) may depend on Node core modules like events. In this case Webpack attempts to shim it with node-libs-browser. However it only attempts to shim it if it can't resolve the module name using the regular mechanism. The problem is that some Linux distributions include Node sources into NODE_PATH. Therefore, since we honor NODE_PATH, Webpack finds events in Node.js sources on those systems, and thus doesn't attempt to shim it. As a result you get the latest version from Node.js itself which is likely incompatible with the browsers.

To fix this, we need a way to not allow Node.js core modules to resolve to Node.js sources even if they exist in NODE_PATH. I don't see any easy way to do this. However we can sidestep the issue by not respecting absolute paths in NODE_PATH. The only reason we added NODE_PATH support is for absolute imports (NODE_PATH=src npm start), where NODE_PATH itself is relative. Any other uses of it are inherently dangerous (and won't work across systems anyway). So I think it should be safe to just stop honoring absolute NODE_PATH altogether, thus solving both issues.

It is technically a breaking change but for a use case we never intended to support. I have a hard time believing anyone could've intentionally relied on this, and if it breaks anyone, it will more likely uncover a bug. Therefore I think this is safe to go in 0.8.x, especially given that it fixes more egregious bugs that have been affecting people for months, and 0.8 has been out for just four days.

Assignee
Assign to
Reviewers
Request review from
Time tracking
Source branch: github/fork/gaearon/only-honor-relative-node-path