mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
bd2c57569b
Summary:
Not totally sure if this is the best way to handle this. In Venice if a native module is missing I try to log the name of the module, but I noticed that the error I was getting was getting this:
{F161460962}
Presumably this is because importing from NativeModules looks for `__esModule`, but NativeModules uses `module.export`. So it's trying to access that property on my cpp proxy object, which doesn't exist...? Changing TurboModuleProxy to use `require` seems to fix the problem.
Reviewed By: fkgozali
Differential Revision: D15787508
fbshipit-source-id: 4b9df4e3c179117999fe6de6363edbef427a8263
45 lines
1.1 KiB
JavaScript
45 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @flow
|
|
* @format
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const NativeModules = require('../BatchedBridge/NativeModules');
|
|
import type {TurboModule} from './RCTExport';
|
|
import invariant from 'invariant';
|
|
|
|
const turboModuleProxy = global.__turboModuleProxy;
|
|
|
|
export function get<T: TurboModule>(name: string): ?T {
|
|
if (turboModuleProxy != null) {
|
|
const module: ?T = turboModuleProxy(name);
|
|
if (module != null) {
|
|
return module;
|
|
}
|
|
}
|
|
|
|
// Backward compatibility layer during migration.
|
|
const legacyModule = NativeModules[name];
|
|
if (legacyModule != null) {
|
|
return ((legacyModule: any): T);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
export function getEnforcing<T: TurboModule>(name: string): T {
|
|
const module = get(name);
|
|
invariant(
|
|
module != null,
|
|
`TurboModuleRegistry.getEnforcing(...): '${name}' could not be found. ` +
|
|
'Verify that a module by this name is registered in the native binary.',
|
|
);
|
|
return module;
|
|
}
|