react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Unable to resolve module node:http

Open jimmywarting opened this issue 2 years ago • 3 comments

Description

Just forwarding a issue from our orgi to you...

fyi, I Don't have any involvement with react-native. but it seems like you guys have an issue resolving node modules beginning with a node: prefix / protocol

Version

n/a

Output of npx react-native info

n/a

Steps to reproduce

n/a

Description?

I'm working on a ReactNative app, and I was trying to make an HTTP request on an API. The implementation i have workes (I've been using it for a while now).

Screen Shot 2022-01-29 at 20 46 47

But with this new version 3.2.0, when i import the file, I immediately get Unable to resolve module node:http in my the console cmd, and also this suggestion below.

If you are sure the module exists, try these steps:

  1. Clear watchman watches: watchman watch-del-all
  2. Delete node_modules and run yarn install
  3. Reset Metro's cache: yarn start --reset-cache
  4. Remove the cache: rm -rf /tmp/metro-*

Reproduction Steps to reproduce the behavior:

  1. yarn add node-fetch
  2. run the code above ( image )

Expected behavior

Screenshots Screen Shot 2022-01-29 at 20 51 57

Snack, code example, screenshot, or link to a repository

No response

jimmywarting avatar Jan 29 '22 19:01 jimmywarting

@jimmywarting just wondering, why are you using node-fetch? React-native bundles the fetch API out-of-the-box. No need to use node-fetch. (no need to import any lib, it's available at the global scope).

By the way, even if metro was able to import this library it would break when running on device. You see, node-fetch depends on the NodeJS environment which Android or iOS does not support. (You can't run NodeJS modules on the device - I mean modules that use the NodeJS api itself - which is your case)

cabelitos avatar Feb 25 '22 23:02 cabelitos

i'm not using react-native, it was an other developer that had a problem with this. he had problem with node: prefixes

jimmywarting avatar Feb 25 '22 23:02 jimmywarting

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] avatar Aug 27 '22 02:08 github-actions[bot]

This issue was closed because it has been stalled for 7 days with no activity.

github-actions[bot] avatar Sep 11 '22 02:09 github-actions[bot]