Я новичок в NativeScript. Я пробовал пользователя SQLite с TypeORM. Когда я создаю соединение, я получаю ошибки. Вы можете помочь?
Сервисный код:
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);
}
}
}
Errors:
WARNING in ../node_modules/typeorm/browser/driver/react-native/ReactNativeDriver.js
Module not found: Error: Can't resolve 'react-native-sqlite-storage' in '/Users/Compik/Documents/Projects/limu/limu-native/node_modules/typeorm/browser/driver/react-native'
@ ../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 compilation complete. Watching for file changes.
Webpack build done!
Project successfully prepared (ios)
Successfully transferred all files on device FD96C24D-FEB6-49AB-BF10-3D3A09F312BD.
Restarting application on device FD96C24D-FEB6-49AB-BF10-3D3A09F312BD...
***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1 0x1080c780e NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
2 0x108119784 -[TNSRuntime executeModule:referredBy:]
3 0x1079cad33 main
4 0x7fff5227ec25 start
5 0x1
JavaScript stack trace:
../node_modules/pbkdf2/lib/default-encoding.js(file: node_modules/pbkdf2/lib/default-encoding.js:3:11)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ../node_modules/pbkdf2/lib/sync.js(file: node_modules/pbkdf2/lib/sync.js:14:30)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ../node_modules/pbkdf2/index.js(file: node_modules/pbkdf2/index.js:24:31)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ../node_modules/crypto-browserify/index.js(file: node_modules/crypto-browserify/index.js:14:16)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ../node_modules/typeorm/browser/util/StringUtils.js(file: node_modules/typeorm/browser/util/StringUtils.js:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ../node_modules/typeorm/browser/naming-strategy/DefaultNamingStrategy.js(file: node_modules/typeorm/browser/naming-strategy/DefaultNamingStrategy.js:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file:
JavaScript error:
file: node_modules/pbkdf2/lib/default-encoding.js:3:11: JS ERROR TypeError: undefined is not an object (evaluating 'global.process.browser')
(CoreFoundation) *** Terminating app due to uncaught exception 'NativeScript encountered a fatal error: TypeError: undefined is not an object (evaluating 'global.process.browser')
at
../node_modules/pbkdf2/lib/default-encoding.js(file: node_modules/pbkdf2/lib/default-encoding.js:3:11)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ../node_modules/pbkdf2/lib/sync.js(file: node_modules/pbkdf2/lib/sync.js:14:30)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ../node_modules/pbkdf2/index.js(file: node_modules/pbkdf2/index.js:24:31)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ../node_modules/crypto-browserify/index.js(file: node_modules/crypto-browserify/index.js:14:16)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ../node_modules/typeorm/browser/util/StringUtils.js(file: node_modules/typeorm/browser/util/StringUtils.js:1:0)
at __webpack_require__(file: src/webpack/bootstrap:750:0)
at fn(file: src/webpack/bootstrap:120:0)
at ../
NativeScript caught signal 6.
Native Stack:
1 0x1081183e1 sig_handler(int)
2 0x7fff5245b42d _sigtramp
3 0x1
4 0x7fff5234ba5c abort
5 0x7fff502497f8 __cxa_bad_cast
6 0x7fff502499c7 demangling_unexpected_handler()
7 0x7fff513fbd7c _objc_terminate()
8 0x7fff50256e97 std::__terminate(void (*)())
9 0x7fff502568fe __cxa_get_exception_ptr
10 0x7fff502568c5 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*)
11 0x7fff513fbc44 _objc_exception_destructor(void*)
12 0x1080c7d4f NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool)
13 0x108119784 -[TNSRuntime executeModule:referredBy:]
14 0x1079cad33 main
15 0x7fff5227ec25 start
16 0x1
JS Stack: