Skip to content

react-native: node:http could not be found #91

@homersimpsons

Description

@homersimpsons

Environment

  • react-native: 0.71.0
  • ofetch: 1.1.0

Reproduction

  1. Start a react-native project
  2. yarn add [email protected]
  3. Add a request: ofetch('www.example.com')
  4. Notice the bug

Describe the bug

I just tried this on react-native (after unjs/ofetch#206) and it looks like it does not work because of node:http:

node:http could not be found within the project or in these directories

Screenshot (Jun 20, 2023 17 46 46)

Additional context

No response

Logs

error: Error: Unable to resolve module node:http from /homer/user/project/node_modules/ofetch/dist/node.cjs: node:http could not be found within the project or in these directories:
  node_modules
  ../../node_modules
  1 | 'use strict';
  2 |
> 3 | const http = require('node:http');
    |                       ^
  4 | const https = require('node:https');
  5 | const nodeFetch = require('node-fetch-native');
  6 | const fetch$1 = require('./shared/ofetch.0fda5c9e.cjs');
    at ModuleResolver.resolveDependency (/homer/user/project/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:162:15)
    at DependencyGraph.resolveDependency (/homer/user/project/node_modules/metro/src/node-haste/DependencyGraph.js:260:43)
    at Object.resolve (/homer/user/project/node_modules/metro/src/lib/transformHelpers.js:177:21)
    at Graph._resolveDependencies (/homer/user/project/node_modules/metro/src/DeltaBundler/Graph.js:432:35)
    at Graph._processModule (/homer/user/project/node_modules/metro/src/DeltaBundler/Graph.js:218:38)
    at async Graph._addDependency (/homer/user/project/node_modules/metro/src/DeltaBundler/Graph.js:314:20)
    at async Promise.all (index 0)
    at async Graph._processModule (/homer/user/project/node_modules/metro/src/DeltaBundler/Graph.js:263:5)
    at async Graph._traverseDependenciesForSingleFile (/homer/user/project/node_modules/metro/src/DeltaBundler/Graph.js:207:5)
    at async Graph.traverseDependencies (/homer/user/project/node_modules/metro/src/DeltaBundler/Graph.js:147:9)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions