For a little test project i've tried to start a NativeScript (Angular flavor) with a sqlite db and typeorm.
ns create sample-typeorm --ng
cd sample-typeorm
ns plugin add nativescript-sqlite
npm i typeorm stream-browserify timers-browserify
Because of the missing nodejs modules "stream" and "timers" my tsconfig.json
looks like
{
"compilerOptions": {
"module": "esnext",
"target": "es2017",
"moduleResolution": "node",
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"noEmitHelpers": true,
"noEmitOnError": true,
"skipLibCheck": true,
"lib": [
"es2018",
"es2017",
"dom",
"es6"
],
"baseUrl": ".",
"paths": {
"~/*": [
"app/*"
],
"timers": [
"node_modules/timers-browserify"
],
"stream": [
"node_modules/stream-browserify"
]
}
},
"include": [
"src/tests/**/*.ts",
"src/**/*.ios.ts",
"src/**/*.android.ts"
],
"files": [
"./references.d.ts",
"./src/main.ts"
],
"exclude": [
"node_modules",
"platforms",
"e2e"
]
}
To start the typoeorm/sqlite test, i added in my src/main.ts
the "createConnection" stuff:
// this import should be first in order to load some required settings (like globals and reflect-metadata)
import {platformNativeScriptDynamic} from "@nativescript/angular";
import {AppModule} from "./app/app.module";
import {createConnection} from "typeorm/browser";
let driver = require('nativescript-sqlite');
platformNativeScriptDynamic().bootstrapModule(AppModule);
(async () => {
try {
const connection = await createConnection({
database: 'test.db',
type: 'nativescript',
entities: [
//... whatever entities you have
],
driver,
logging: true,
synchronize: false
})
} catch (e) {
console.error(e)
}
;
})();
I startet the app
ns run ios --emulator
After a little bit of working time for the build system the following error appear:
ERROR in ../node_modules/app-root-path/lib/resolve.js
Module not found: Error: Can't resolve 'module' in '/private/tmp/sample-typeorm/node_modules/app-root-path/lib'
@ ../node_modules/app-root-path/lib/resolve.js 7:18-35
@ ../node_modules/app-root-path/lib/app-root-path.js
@ ../node_modules/app-root-path/index.js
@ ../node_modules/typeorm/browser/connection/ConnectionOptionsReader.js
@ ../node_modules/typeorm/browser/index.js
@ ./main.ts
In the node_modules/app-root-path/lib/resolve.js
is the source of the error:
var globalPaths = require('module').globalPaths;
Is there a browserify equivalent for the "module" module? Or is there an option for the webpack to avoid this error?
To get a step forward i modified the resolve.js
to skip the "module" and ran into the next error, which let me thinking about that i have another missing/miss configured webpack option:
Terminating app due to uncaught exception 'NativeScript encountered a fatal error: Uncaught TypeError: Cannot destructure property 'env' of 'global.process' as it is undefined.
at
../node_modules/supports-color/index.js(file: node_modules/supports-color/index.js:6:7)
In the node_modules/supports-color/index.js
is this:
const {env} = process;
The webpack.config.js
is untouched from the "ns create ...".
Have anyone a running typeorm sample for NativeScript 7? Or an idea which module is missing?
npm i module
which lead to your last error. Typeorm is a great lib lets hope someone can shed light on how to resolve. - Edwin Quai Hoi