在项目外导入基于本机的共享组件期间,未注册模块AppRegistry可调用模块错误

问题描述 投票:0回答:1

今天,当我决定重用某些组件时遇到了一个错误。

我有一些React Native项目,我想遵循DRY原则,以避免代码重复。我想将组件导入到完全基于“本机”库且位于项目根目录之外的项目中。但是,我收到一个错误:

Error Screenshot

Project Structure

附加:

  1. mobile / babel.config.js
  2. mobile / metro.config.js
// mobile/babel.config.js
const moduleResolverPluginConfig = [
  'module-resolver', {
    alias: {
      'common': '../common'
    }
  }
]

module.exports = {
  presets: ['module:metro-react-native-babel-preset'],
  plugins: [moduleResolverPluginConfig]
}

// mobile/metro.config.js
const path = require('path')

const commonLibRoot = path.resolve(__dirname, '../common')
const projectRoot = path.resolve()

module.exports = {
  projectRoot,
  watchFolders: [commonLibRoot],
  resolver: {
    extraNodeModules: {
      'common': commonLibRoot
    }
  },
  transformer: {
    getTransformOptions: async () => ({
      transform: {
        experimentalImportSupport: false,
        inlineRequires: false
      }
    })
  }
}

我将不胜感激!

react-native native-base
1个回答
0
投票

当我在项目中遇到这些“模块AppRegistry未注册”错误时,重新启动服务器将为我工作。尝试重新启动服务器

© www.soinside.com 2019 - 2024. All rights reserved.