我想在我的React Native包中導入ReactNativePropRegistry。在反應本機中有條件地解析模塊
我曾經在React Native 0.38.0之前將它從'react/lib/ReactNativePropRegistry'
導入,但它在React Native 0.38.0中更改爲'react-native/Libraries/Renderer/src/renderers/native/ReactNativePropRegistry'
。
我要支持所有的陣營原生版本,包括0.38.0我的包,所以我做了這個
if(semver.gte(reactNativeVersion, '0.38.0-rc.0')) {
const ReactNativePropRegistry = require('react-native/Libraries/Renderer/src/renderers/native/ReactNativePropRegistry');
} else {
const ReactNativePropRegistry = require('react/lib/ReactNativePropRegistry');
}
但似乎打包嘗試靜態解析模塊。因此,即使reactNativeVersion小於0.38.0-rc.0,它也會嘗試在此路徑上解析模塊'react-native/Libraries/Renderer/src/renderers/native/ReactNativePropRegistry'
,從而導致它引發錯誤Unable to resolve module ...
。
有沒有辦法解決這個問題?