Skip to content

Can't use in React Native #88

@tinaroh

Description

@tinaroh

I'm trying to use this library in a React Native app for localization but I'm having trouble with the following error:

Error: Unable to resolve module `assert` from `/Users/tinaroh/Dev/Raha/raha-mobile-app/node_modules/cldr-data/index.js`: Module `assert` does not exist in the Haste 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-*`.
    at ModuleResolver.resolveDependency (/Users/tinaroh/Dev/Raha/raha-mobile-app/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:209:1301)
    at ResolutionRequest.resolveDependency (/Users/tinaroh/Dev/Raha/raha-mobile-app/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:83:16)
    at DependencyGraph.resolveDependency (/Users/tinaroh/Dev/Raha/raha-mobile-app/node_modules/metro/src/node-haste/DependencyGraph.js:238:485)
    at Object.resolve (/Users/tinaroh/Dev/Raha/raha-mobile-app/node_modules/metro/src/lib/transformHelpers.js:180:25)
    at dependencies.map.result (/Users/tinaroh/Dev/Raha/raha-mobile-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:311:29)
    at Array.map (<anonymous>)
    at resolveDependencies (/Users/tinaroh/Dev/Raha/raha-mobile-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:307:16)
    at /Users/tinaroh/Dev/Raha/raha-mobile-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:164:33
    at Generator.next (<anonymous>)
    at step (/Users/tinaroh/Dev/Raha/raha-mobile-app/node_modules/metro/src/DeltaBundler/traverseDependencies.js:266:307)

I tried the listed workarounds in the mentioned issue but have had no luck.

For set up I did: yarn add react-globalize cldr-data (we use yarn instead of npm)

Initialization in the file with the component:

var ReactGlobalize = require("react-globalize");
var Globalize = require("globalize");
Globalize.load(require("cldr-data").entireSupplemental());
Globalize.load(require("cldr-data").entireMainFor("en", "de"));

Call-site in the render function within the same file:

{new Globalize("de").numberFormatter({ minimumFractionDigits: 2 })(10)}

(tried the static version too)

I'm pretty new to JavaScript/React. I heard that there are differences with the React Native JS and web JS, could that be what's tripping this up? Though I feel like assert should be in both... Is there something special I need to do for React Native?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions