react-native - 带有 React Native 的 TypeORM
问题描述
我创建了一个新的虚拟应用程序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
这是显示问题的示例存储库:在此处输入链接描述
不确定我是否错过了设置中的某些内容!非常欢迎任何帮助!
解决方案
不幸的是,从“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,
],
})
推荐阅读
- python - 如何使用 Boto3 SDK 为 SageMaker 训练作业指定源目录和入口点?用例是通过 Lambda 调用开始训练
- bootstrap-5 - 导航中带有两个单词的引导按钮会导致第二个单词换行
- mysql - SQL 过滤掉与条件匹配的字符串,并有特定的异常通过
- xaml - 有没有办法将一个 Xamarin Forms 控件与另一个“关联”?
- django - Django get request.POST.get() 参数未按预期工作,带括号的参数名称 []
- sql - Laravel Eloquent 如何从日期范围内的 2 个表中获取数据
- r - 有没有办法为使用具有填充美学的因子变量的 ggplot 条形图提供 n 个计数?
- node.js - 如何将基于 Node js 的网站转换为移动应用程序?
- python - Python - 如何通过 Selenium 发送键发送数值
- spring-boot - 命名休眠查询的列表在哪里?