bttmly / nba

Node.js client for nba.com API endpoints

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot find module 'querystring' when using in React-Native app

fzymek opened this issue · comments

Hello,

I am trying to use this module in react-native app but I am getting following error:

error: bundling failed: Error: Unable to resolve module `querystring` from `/Users/zymfilip/Development/src/NBABrowseApp/node_modules/nba/src/stats.js`: Module does not exist in the module map

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: `watchman watch-del-all`.
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.

I tried proposed solution but it does not work. Here's my env setup:

node v6.13.1
npm v3.10.10
nba v4.2.0

Try nba@4.2.1 – I've removed querystring as a dependency. Please let me know if it works or not when you get a chance!

hmm.. now I am getting the same error but for different module:

Unable to resolve module `url` from `/Users/zymfilip/Development/src/NBABrowseApp/node_modules/nba/src/get-json.js`: Module does not exist in the module map

it seems to be related to react-native and the issue they are mentioning in error log facebook/react-native#4968

I tried creating simple node app and it works without a problem. Both 4.2.0 and 4.2.1

Hm alright yeah so react-native can't pull in Node.js builtin modules (both querystring and url are provided by Node.js but included in the browser build by Browserify).

Question for you: do you have the global URL constructor available in react-native? It's a browser feature https://developer.mozilla.org/en-US/docs/Web/API/URL

I added an explicit url dependency in nba@4.2.2 – can you try that one? Sorry for the back-and-forth

No problem, but still no luck ;(

error: bundling failed: Error: Unable to resolve module `http` from `/Users/zymfilip/Development/src/NBABrowseApp/node_modules/node-fetch/index.js`: Module does not exist in the module map

This might be related to https://github.com/facebook/react-native/issues/4968

Regarding URL, it looks that there are some issues with URL in RN facebook/react-native#16434 lately.

It seems that there are some conflicts as I tried adding dependency on http module in my app and I got following error:

error: bundling failed: Error: While trying to resolve module `http` from file `/Users/zymfilip/Development/src/ReactiveAirQuality/node_modules/node-fetch/index.js`, the package `/Users/zymfilip/Development/src/ReactiveAirQuality/node_modules/http/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/zymfilip/Development/src/ReactiveAirQuality/node_modules/http/index.js`. Indeed, none of these files exist:

  * `/Users/zymfilip/Development/src/ReactiveAirQuality/node_modules/http/index.js(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)`
  * `/Users/zymfilip/Development/src/ReactiveAirQuality/node_modules/http/index.js/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)`

It seems to me (but I might be wrong as I am quite new to node & react-native) that you are using some dependencies not supported in RN. Is it possible?

Yes that's exactly the problem: url, querystring, and http all come from NodeJS – when used outside of Node they need a build step to pull in browser-compatible substitutes for these packages. Can you try the following:

import nba from "nba/dist/nba"

This points directly to the library bundled with all of its dependencies

Still no luck

error: bundling failed: Error: Unable to resolve module `./src` from `/Users/zymfilip/Development/src/ReactiveAirQuality/node_modules/nba/dist/nba.js`: The module `./src` could not be found from `/Users/zymfilip/Development/src/ReactiveAirQuality/node_modules/nba/dist/nba.js`. Indeed, none of these files exist:

  * `/Users/zymfilip/Development/src/ReactiveAirQuality/node_modules/nba/dist/src(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)`
  * `/Users/zymfilip/Development/src/ReactiveAirQuality/node_modules/nba/dist/src/index(.native||.ios.js|.native.js|.js|.ios.json|.native.json|.json)`

Damn. Alright, I'll try compiling it with webpack instead of browserify and see if that helps. I'll get back to you in a couple days

same issue here.

This totally slipped my mind. Now that the season is about to start... I just published nba@4.3.2 can someone try using import nba from "nba/dist/webpacked"?

just use npm install querystring
it works for me

great! closing, but if someone else runs into a similar problem please open an issue

@MatthewDevelop Just porting a node crypto dependant project into react-native and solved that package's querystring dependency like this!
Love you

just use npm install querystring
it works for me

Works for me too :)