gpt4 book ai didi

react-native - TypeORM 与 React Native

转载 作者:IT王子 更新时间:2023-10-29 06:29:09 28 4
gpt4 key购买 nike

我使用 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

不确定我是否遗漏了设置中的某些内容!非常欢迎任何帮助!

最佳答案

不幸的是,从“typeorm”模块导入不起作用,因为 react-native 项目不使用 node 平台。从“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,
],
})

关于react-native - TypeORM 与 React Native,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50117535/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com