Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React-Native-Web. Build Error - Unable to resolve "./RCTNetworking" #2734

Open
1 task done
CaptainJeff opened this issue Nov 4, 2024 · 0 comments
Open
1 task done
Labels

Comments

@CaptainJeff
Copy link

CaptainJeff commented Nov 4, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the issue

When I'm trying to build the project I run into the error

Unable to resolve "./RCTNetworking" from "node_modules/react-native/Libraries/Network/XMLHttpRequest.js"

Seems like the issue is node_modules/react-native/Libraries/Network directory has an RCTNetworking.android.js and RCTNetworking.ios.js but the metro.config.js can't find a corresponding file for web.

I have a dependency that makes my API requests with axios (that i access from my npm module / not directly from my app components/stores.

I've tried mocking out the RCTNetworking but can't seem to get anything to work. It will either not make the request or will fail with the same import error.

For instance if I do

if (moduleName.endsWith("RCTNetworking")) {
      return {
        filePath: require.resolve("identity-obj-proxy"),
        type: "sourceFile"
      }
    }

It hides the error on build but I can't make HTTP calls and gives me the following error when I try to make an API request

TypeError: Cannot read properties of undefined (reading 'default')
    at XMLHttpRequest.send (XMLHttpRequest.js:527:7)
    at dispatchXhrRequest (xhr.js:195:13)
    at tryCallTwo (core.js:45:5)
    at doResolve (core.js:200:13)
    at new Promise (core.js:66:3)
    at xhr (xhr.js:15:10)
    at ThrottlingAdapter.<anonymous> (adapter.js:186:40)
    at Generator.next (<anonymous>)
    at adapter.js:8:71
    at tryCallTwo (core.js:45:5)
    at Axios.request (Axios.js:45:41)

Expected behavior

Would expect to compile and be able to make API requests.

Steps to reproduce

  1. npx expo start --web -c

"react-native": "0.74.2",
"expo": "^51.0.0"

Test case

N/A

Additional comments

No response

@CaptainJeff CaptainJeff added the bug label Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant