Typeorm与本机反应

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

我用react-native init test创建了一个新的虚拟应用程序,然后按照说明添加了typeorm。在我的App.js中,我包括import {getManager} from 'typeorm',然后运行react-native run-ios

我在metro-bundler中看到以下错误:

Error: Unable to resolve module path from /Users/amit/Code/test/node_modules/typeorm/platform/PlatformTools.js: Module path does not exist in the Haste module map

这是一个展示问题的示例存储库:enter link description here

不确定我是否错过了设置中的内容!真的很受欢迎!

react-native sqlite typeorm
1个回答
2
投票

不幸的是,从'typeorm'模块导入不起作用,因为react-native项目不会兴奋地使用节点平台。来自'typeorm / browser'的导入将起作用。这是一个示例项目:https://github.com/typeorm/react-native-example

确保创建一个不使用对项目文件系统的任何引用的连接对象。避免使用以下内容:

import { CountSession } from '../biopro-mobile-database/entities/count_session';

   const connection = await createConnection({
            name: 'liteDb_3',
            type: 'react-native',
            database: 'biopro_mobile.sqlite',
            location: 'default',
            synchronize: false,
            logging: true,
            entities: ["../biopro-mobile-database/entities/**/*.ts"],
          })

避免实体:[“../biopro-mobile-database/entities//*.ts"],**而是使用类似的东西:

import { EquipmentCounted } from '../biopro-mobile-database/entities/equipment_counted';
import { CountSession } from '../biopro-mobile-database/entities/count_session';

   const connection = await createConnection({
            name: 'liteDb_3',
            type: 'react-native',
            database: 'biopro_mobile.sqlite',
            location: 'default',
            synchronize: false,
            logging: true,
            entities: [
              CountSession,
              EquipmentCounted,
            ],
          })
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.