我在 React Native 中使用条件导入时遇到了一些麻烦。
我有一些在 React Web 应用程序和 React Native 中使用的文件。
我想要什么:
if(process.env.REACT_PLATFORM === 'WEB') {
import('some_file').then(({someFunc})=> someFunc())
}
因为 'some_file' 导入react_router.
然而,这个导入仍在发生,RN 地铁打包器抛出
UnableToResolveError: Unable to resolve module 'react-router' from 'some_file'.
即使我将其替换为:
if(false) {
import('some_file').then(({someFunc})=> someFunc())
}
它仍然尝试加载some_file. 无论如何,如果满足条件,是否只导入/需要此文件?
干杯!
编辑:我尝试过的事情: