nanoid: Recently installed in an Expo 37/RN app, getting TypeError: null is not an object (evaluating 'RNGetRandomValues.getRandomBase64')

As stated in the title, recently installed it into an Expo 37 app as I was all of a sudden getting errors using uuid.V4. Followed the instructions and made sure I installed and imported ‘react-native-get-random-values’ (both at the top of my index.js entry point of the app, and every where else I used nanoid.

On starting the app I get this error:

TypeError: null is not an object (evaluating 'RNGetRandomValues.getRandomBase64')

getRandomValues
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:126457:35
nanoid
    index.browser.js:80:2
arr.map$argument_0
    grape-varietals.js:10:18
map
    [native code]:0
<global>
    grape-varietals.js:9:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:126380:39
loadModuleImplementation
    require.js:322:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:126309:36
loadModuleImplementation
    require.js:322:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:126059:61
loadModuleImplementation
    require.js:322:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:126024:53
loadModuleImplementation
    require.js:322:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:124002:50
loadModuleImplementation
    require.js:322:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:123965:50
loadModuleImplementation
    require.js:322:6
<global>
    AppEntry.js:3
loadModuleImplementation
    require.js:322:6
guardedLoadModule
    require.js:201:45
global code
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:165136:4

rng
    rng-browser.js:16:7
v4
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:126911:63
arr.map$argument_0
    grape-varietals.js:9:18
map
    [native code]:0
<global>
    grape-varietals.js:8:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:126376:39
loadModuleImplementation
    require.js:322:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:126307:36
loadModuleImplementation
    require.js:322:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:126057:61
loadModuleImplementation
    require.js:322:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:126022:53
loadModuleImplementation
    require.js:322:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:124000:50
loadModuleImplementation
    require.js:322:6
<unknown>
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:123965:50
loadModuleImplementation
    require.js:322:6
<global>
    AppEntry.js:3
loadModuleImplementation
    require.js:322:6
guardedLoadModule
    require.js:201:45
global code
    AppEntry.bundle?platform=ios&dev=true&minify=false&hot=false:165602:4

I am implementing in my code like this:

import 'react-native-get-random-values';
import { nanoid } from 'nanoid';
// other code
const createVarietalArray = (arr, color, common) => {
  return arr.map(v => new Varietal(nanoid(), color, v, false, common));
};

const COMMON_RED = createVarietalArray(redVarietals.common, 'red', true);

Any idea what might be causing this?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 57 (28 by maintainers)

Commits related to this issue

Most upvoted comments

p.s. I see you have a keen interest in space. Same here! Not sure if this is the right place but I make and mix a lot of ‘space-inspired’ music. Have a listen here if you like: https://soundcloud.com/deejay-hazy/sets/floating-in-space And if this is not really github eitiquette then let me know and I will delete this message…

I can add special version of nanoid/async for React Native, which will use and require expo.

BTW If import like 'nanoid/async/index.native' (w/o extension) then linter have no complaints. Only vscode still reminds about types: Could not find a declaration file for module 'nanoid/async/index.native'.