react / react/metro

Enable Virtual Module Resolution

Open
#1,422 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Type: Feature Request
Dominant language
JavaScript
Stars
5.6k
Forks
696
Avg merge
8m
Merged PRs (30d)
7

Description

Overview

To implement a custom resolution system that allows resolving virtual modules and handles cases where files have not been created yet, you can extend the Metro resolver with a custom resolveRequest function. This function will provide a VirtualResolution for modules that don’t exist physically but are dynamically generated or virtualized.

resolveRequest?: CustomResolver;

export type CustomResolver = (
  context: CustomResolutionContext,
  moduleName: string,
  platform: string | null,
) => Resolution;

export type Resolution = FileResolution | VirtualResolution 
 | Readonly<{type: 'empty'}>;

export type FileResolution = AssetResolution | SourceFileResolution;

export type AssetResolution = Readonly<{
  type: 'assetFiles';
  filePaths: AssetFileResolution;
}>;

export type SourceFileResolution = Readonly<{
  type: 'sourceFile';
  filePath: string;
}>;

export type VirtualResolution = Readonly<{
  type: 'virtual';
  content: string;
}>;

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing Metro's custom resolveRequest hook and the Resolution types shown in the issue. Review how existing file, asset, and empty resolutions are handled, then define and test the behavior for a virtual resolution whose content comes from a module that does not exist on disk.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
build-system, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.