Can't resolve 'react-native-sqlite-storage'

54 Views Asked by At

In my project I use typeorm , I install version 0.3.20 but in project ionic 5 with angular 12 but now i found this error:

"Module not found: Error: Can't resolve 'react-native-sqlite-storage' in '/node_modules/typeorm/browser/driver/react-native'"

this is package.json:

    {
  "name": "test",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "https://ionicframework.com/",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration development",
    "test": "ng test",
    "lint": "ng lint",
    "postinstall": "ngcc"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^12.2.17",
    "@angular/common": "^12.2.17",
    "@angular/compiler": "^12.2.17",
    "@angular/core": "^12.2.17",
    "@angular/forms": "^12.2.17",
    "@angular/platform-browser": "^12.2.17",
    "@angular/platform-browser-dynamic": "^12.2.17",
    "@angular/router": "^12.2.17",
    "@ionic-native/core": "5.36.0",
    "@ionic-native/network": "5.36.0",
    "@ionic-native/splash-screen": "5.36.0",
    "@ionic-native/sqlite": "^5.36.0",
    "@ionic-native/status-bar": "5.36.0",
    "@ionic/angular": "^5.9.4",
    "@ionic/storage": "2.1.3",
    "@ngui/auto-complete": "^3.0.0",
    "@okta/okta-auth-js": "7.5.1",
    "@types/lodash": "4.14.116",
    "angular-oauth2-oidc": "12.1.0",
    "angular2piwik": "0.1.5-beta",
    "bootstrap": "5.3.3",
    "classlist.js": "^1.1.20150312",
    "cordova-android": "^11.0.0",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-sqlite-storage": "^6.0.0",
    "core-js": "^3.36.0",
    "flickity": "2.1.2",
    "font-awesome": "4.7.0",
    "intl": "^1.2.5",
    "ionic-plugin-keyboard": "^2.2.1",
    "ionicons": "^5.0.0",
    "jquery": "3.2.1",
    "karma": "^6.0.0",
    "karma-chrome-launcher": "^3.2.0",
    "karma-coverage-istanbul-reporter": "^3.0.3",
    "karma-jasmine": "^5.1.0",
    "karma-jasmine-html-reporter": "^1.7.0",
    "karma-junit-reporter": "^2.0.1",
    "moment": "2.22.2",
    "popper.js": "1.12.6",
    "postcss-px2rem-exclude": "^0.0.6",
    "puppeteer": "^5.2.1",
    "reflect-metadata": "^0.2.1",
    "rxjs": "~6.5.5",
    "sqlite3": "^5.1.7",
    "sw-toolbox": "3.6.0",
    "tslib": "^2.3.0",
    "typeorm": "^0.3.20",
    "web-animations-js": "^2.2.5",
    "zone.js": "0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^12.0.0",
    "@angular-eslint/builder": "^12.0.0",
    "@angular-eslint/eslint-plugin": "^12.0.0",
    "@angular-eslint/eslint-plugin-template": "^12.0.0",
    "@angular-eslint/schematics": "^12.0.0",
    "@angular-eslint/template-parser": "^12.0.0",
    "@angular/cli": "^12.0.0",
    "@angular/compiler-cli": "^12.0.0",
    "@angular/language-service": "^12.0.0",
    "@ionic/angular-toolkit": "^4.0.0",
    "@types/jasmine": "~5.1.0",
    "@types/node": "^14.14.31",
    "@typescript-eslint/eslint-plugin": "^6.0.0",
    "@typescript-eslint/parser": "^6.0.0",
    "babel-plugin-react-native-web": "^0.19.10",
    "cordova-plugin-androidx-adapter": "^1.1.3",
    "cordova-plugin-inappbrowser": "^5.0.0",
    "cordova-plugin-ionic-webview": "^5.0.0",
    "cordova-plugin-network-information": "^3.0.0",
    "eslint": "^7.26.0",
    "eslint-plugin-import": "2.22.1",
    "eslint-plugin-jsdoc": "30.7.6",
    "eslint-plugin-prefer-arrow": "1.2.2",
    "typescript": "~4.2.3"
  },
  "description": "An Ionic project"
}

node version used is v16.20.0 and for typescript is 4.2.3

how to resolve this error please

1

There are 1 best solutions below

0
hanghang dragon On

I found a solution for that. I have read the package.json of typeorm, and found out that typeorm imports different libraries for different environment (node or browser). In some cases, we want to use database server-side, however, typeorm is seen as a client-side dependency, and it will assume it's under browser environment and require react-native packages. To handle this, just add this into your project's package.json:

  "browser": {
    "typeorm": false
  }