【发布时间】:2025-12-05 15:15:01
【问题描述】:
我是 NativeScript 的新手。 我用 TypeORM 尝试了用户 SQLite。 创建连接时出现错误。 你能帮忙吗?
服务代码:
import { createConnection, Connection, ConnectionOptions, getConnection } from "typeorm/browser";
let driver = require("nativescript-sqlite");
// let driver = require("nativescript-sqlite");
@Injectable({
providedIn: "root"
})
export class DatabaseService {
private dbConnection: Connection;
constructor() {
this.initDB();
}
/* async createDb() {
const db = new driver("limu.db").
};
*/
async initDB() {
try {
this.dbConnection = await getConnection();
// this.dbTasksRepository = await this.dbConnection.getRepository(TaskEntity);
} catch (error) {
console.log('!!!erorr', error);
await this.createConnection();
// this.dbTasksRepository = await this.dbConnection.getRepository(TaskEntity);
}
}
private async createConnection() {
let dbOptions: ConnectionOptions;
dbOptions = {
type: "nativescript",
driver,
database: "limu.db",
entities: [
TaskEntity
],
logging: ["error", "query", "schema"],
synchronize: true
};
try {
this.dbConnection = await createConnection(dbOptions);
} catch (error) {
console.log(error);
}
}
}
错误:
../node_modules/typeorm/browser/driver/react-native/ReactNativeDriver.js 中的警告
找不到模块:错误:无法解析“/Users/Compik/Documents/Projects/limu/limu-native/node_modules/typeorm/browser/driver/react-native”中的“react-native-sqlite-storage”
@ ../node_modules/typeorm/browser/driver/react-native/ReactNativeDriver.js
@ ../node_modules/typeorm/browser/driver/DriverFactory.js
@ ../node_modules/typeorm/browser/connection/Connection.js
@ ../node_modules/typeorm/browser/index.js
@ ./app/core/database/database.service.ts
@ ./app/app.component.ts
@ ./app/app.module.ts
@ ./main.ts
Webpack 编译完成。监视文件更改。
Webpack 构建完成!
项目准备成功(ios)
成功传输设备 FD96C24D-FEB6-49AB-BF10-3D3A09F312BD 上的所有文件。
重启设备 FD96C24D-FEB6-49AB-BF10-3D3A09F312BD 上的应用程序...
***** 致命的 JavaScript 异常 - 应用程序已终止。 *****
本机堆栈跟踪:
1 0x1080c780e NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
2 0x108119784 -[TNSRuntime executeModule:referredBy:]
3 0x1079cad33 主要
4 0x7fff5227ec25 开始
5 0x1
JavaScript 堆栈跟踪:
../node_modules/pbkdf2/lib/default-encoding.js(文件:node_modules/pbkdf2/lib/default-encoding.js:3:11)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:src/webpack/bootstrap:120:0)
在../node_modules/pbkdf2/lib/sync.js(文件:node_modules/pbkdf2/lib/sync.js:14:30)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:src/webpack/bootstrap:120:0)
在 ../node_modules/pbkdf2/index.js(文件:node_modules/pbkdf2/index.js:24:31)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:src/webpack/bootstrap:120:0)
在 ../node_modules/crypto-browserify/index.js(文件:node_modules/crypto-browserify/index.js:14:16)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:src/webpack/bootstrap:120:0)
在 ../node_modules/typeorm/browser/util/StringUtils.js(文件:node_modules/typeorm/browser/util/StringUtils.js:1:0)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:src/webpack/bootstrap:120:0)
在../node_modules/typeorm/browser/naming-strategy/DefaultNamingStrategy.js(文件:node_modules/typeorm/browser/naming-strategy/DefaultNamingStrategy.js:1:0)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:
JavaScript 错误:
文件:node_modules/pbkdf2/lib/default-encoding.js:3:11: JS ERROR TypeError: undefined is not an object (evalating 'global.process.browser')
(CoreFoundation)***由于未捕获的异常而终止应用程序'NativeScript遇到致命错误:TypeError:未定义不是对象(评估'global.process.browser')
在
../node_modules/pbkdf2/lib/default-encoding.js(文件:node_modules/pbkdf2/lib/default-encoding.js:3:11)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:src/webpack/bootstrap:120:0)
在../node_modules/pbkdf2/lib/sync.js(文件:node_modules/pbkdf2/lib/sync.js:14:30)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:src/webpack/bootstrap:120:0)
在 ../node_modules/pbkdf2/index.js(文件:node_modules/pbkdf2/index.js:24:31)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:src/webpack/bootstrap:120:0)
在 ../node_modules/crypto-browserify/index.js(文件:node_modules/crypto-browserify/index.js:14:16)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:src/webpack/bootstrap:120:0)
在 ../node_modules/typeorm/browser/util/StringUtils.js(文件:node_modules/typeorm/browser/util/StringUtils.js:1:0)
在 __webpack_require__(文件:src/webpack/bootstrap:750:0)
在 fn(文件:src/webpack/bootstrap:120:0)
在 ../
NativeScript 捕捉到信号 6。
本机堆栈:
1 0x1081183e1 sig_handler(int)
2 0x7fff5245b42d _sigtramp
3 0x1
4 0x7fff5234ba5c 中止
5 0x7fff502497f8 __cxa_bad_cast
6 0x7fff502499c7 拆解_unexpected_handler()
7 0x7fff513fbd7c _objc_terminate()
8 0x7fff50256e97 标准::__终止(无效(*)())
9 0x7fff502568fe __cxa_get_exception_ptr
10 0x7fff502568c5 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code,_Unwind_Exception*)
11 0x7fff513fbc44 _objc_exception_destructor(无效*)
12 0x1080c7d4f NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
13 0x108119784 -[TNSRuntime executeModule:referredBy:]
14 0x1079cad33 主要
15 0x7fff5227ec25 开始
16 0x1
JS 堆栈:
【问题讨论】:
-
您使用的是哪个版本的 {N}?我不确定为什么它会在类型设置为 nativescript 时尝试获取反应本机驱动程序。你能分享一个可以重现问题的示例项目吗?
-
我使用的是 Nativescript 6.4。链接到项目github.com/compishe/typeORMTest.git
-
由于您的依赖项存在各种错误,我无法运行您的项目,看起来在您运行迁移时出现了问题。
标签: webpack nativescript typeorm