Getting error Unable to resolve module `os` after adding and importing yahoo-finance-data package


#1

Hello, so when I try to import the npm package called “yahoo-finance-data” into my application, I’m getting this error, if I install the package but I don’t import it then I get no error:

Unable to resolve module `os` from `/Users/*/my-app/node_modules/yahoo-finance-data/node_modules/request-promise/lib/rp.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 -fr $TMPDIR/react-*` or `npm start -- --reset-cache`.

ABI22_0_0RCTFBQuickPerformanceLoggerConfigureHooks
ABI23_0_0RCTFBQuickPerformanceLoggerConfigureHooks
<redacted>
<redacted>
<redacted>
<redacted>
<redacted>
CFRunLoopRunSpecific
GSEventRunModal
UIApplicationMain
Exponent
<redacted>

I’m importing it like this:

import YahooFinanceAPI from "yahoo-finance-data";

I already tried doing everything on the steps listed, already did around 10 different solutions found on Github, and restarted my computer but still no luck, the problem also happens when I try it on Snack (https://snack.expo.io/H181pRaQG) do anybody have a solution?


#2

Hey @jeronimocosio,

It looks like the yahoo-finance-data package isn’t built to be used within a react-native project because it has a dependency of request-promise that makes use of Node’s ‘os’ API that isn’t part of RN. From a quick search, it looks like there is a package someone built to expose the ‘os’ API in RN (https://www.npmjs.com/package/react-native-os) but there are two things of note here. 1) It requires you to run react-native link so you would have to detach your Expo project and use ExpoKit and 2) The last push was January of last year so it doesn’t seem to be well maintained.

Cheers,

Adam


#3

Thank you so much for this great answer! I think I will need to create my own package then. :slight_smile:


closed #4

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.