TL;DR
For "Unable to resolve module http from node_modules/@algolia/requester-node-http/src/createHttpRequester.ts": upgrade: npm install algoliasearch@^5.5.1 (or newer 5.x). The maintainers fixed requester selection and released the fix in 5.5.1.
Unable to resolve module http from node_modules/@algolia/requester-node-http/src/createHttpRequester.ts
Steps
- With
algoliasearch 5.x and React Native, Metro fails with:
Unable to resolve module http from node_modules/@algolia/requester-node-http/src/createHttpRequester.ts
- The Node requester imports the
http, https, and url builtins, which Metro
cannot resolve. The same project worked on algoliasearch 4.23.3.
- Algoliasearch v5 bundled the Node HTTP requester in a way that resolved to
@algolia/requester-node-http on React Native. The maintainers fixed requester selection and released the fix in 5.5.1.
- Upgrade:
npm install algoliasearch@^5.5.1 (or newer 5.x). Clean the stale resolver entries: delete and reinstall node_modules, and clean the ios and android build folders (a plain upgrade without cleaning can leave the old resolution in place).
- Rebuild. The reporter confirmed it works after the clean rebuild.
- If you see this same error shape ("Unable to resolve module X from
@algolia/...") on another platform, suspect the requester selection first.
When to use
You are seeing this: The same project worked on algoliasearch 4.23.3. Use this skill when you run into "Algolia v5 breaks React Native: "Unable to resolve module http"".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
Versions mentioned in the source: algoliasearch 4.23.3, 5.5.1. If you are on something much newer or older, the details may have shifted.
Why this happens
Algoliasearch v5 bundled the Node HTTP requester in a way that resolved to @algolia/requester-node-http on React Native.