typeorm: Why is the Typeorm require the react-native-sqlite-storage module that is not using in my project?

Issue type:

[x] question [ ] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [x] mysql / mariadb [ ] oracle [ ] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [ ] react-native [ ] expo

TypeORM version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

Hi ~ When I using typeorm with Next.js react framework… I got the warning message like this.

./node_modules/typeorm/browser/driver/react-native/ReactNativeDriver.js Module not found: Can't resolve 'react-native-sqlite-storage' in '/Users/chicrock/Documents/projects/node_modules/typeorm/browser/driver/react-native'

I only use mysql database in my project.

why is typeorm load the react-native-sqlite-storage module unnecessary to me.

Is this bug ? or something wrong to my usage ?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 12
  • Comments: 26 (6 by maintainers)

Most upvoted comments

👀

I’m using next.js 9.2 with postgresql and I was affected by this too.

@marcorinck solution works without any problem

in my case this created a problem of circular dependency and rejected promise without a catch

this is the log of the problem after I start the server that DOESN’T use sql-lite…

[ wait ]  starting the development server ...
[ info ]  waiting on http://localhost:3000 ...
> Using external babel configuration
> Location: "/Users/{my-user}/path/to/project/.babelrc"
[ warn ]  ./node_modules/typeorm/browser/driver/react-native/ReactNativeDriver.js
Module not found: Can't resolve 'react-native-sqlite-storage' in '/Users/{my-user}/path/to/project/node_modules/typeorm/browser/driver/react-native'
[ info ]  ready on http://localhost:3000
[ event ] build page: /next/dist/pages/_error
[ wait ]  compiling ...
[ warn ]  ./node_modules/typeorm/browser/driver/react-native/ReactNativeDriver.js
Module not found: Can't resolve 'react-native-sqlite-storage' in '/Users/{my-user}/path/to/project/node_modules/typeorm/browser/driver/react-native'
[ info ]  ready on http://localhost:3000
(node:15069) UnhandledPromiseRejectionWarning: TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'NormalModule'
    |     property 'dependencies' -> object with constructor 'Array'
    |     index 0 -> object with constructor 'HarmonyCompatibilityDependency'
    --- property 'originModule' closes the circle
    at JSON.stringify (<anonymous>)
    at /Users/{my-user}/path/to/project/node_modules/webpack-hot-middleware/middleware.js:111:38
    at /Users/{my-user}/path/to/project/node_modules/webpack-hot-middleware/middleware.js:66:7
    at Array.forEach (<anonymous>)
    at everyClient (/Users/{my-user}/path/to/project/node_modules/webpack-hot-middleware/middleware.js:65:26)
    at Object.publish (/Users/{my-user}/path/to/project/node_modules/webpack-hot-middleware/middleware.js:110:7)
    at Function.middleware.publish (/Users/{my-user}/path/to/project/node_modules/webpack-hot-middleware/middleware.js:48:17)
    at HotReloader.send (/Users/{my-user}/path/to/project/node_modules/next/dist/server/hot-reloader.js:5:640)
    at /Users/{my-user}/path/to/project/node_modules/next/dist/server/hot-reloader.js:15:508
    at /Users/{my-user}/path/to/project/node_modules/next/dist/build/output/index.js:5:651
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
(node:15069) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:15069) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

this is a really really weird and unexpected bug…

currently on

    "typeorm": "^0.2.22"

The same happens when using typeorm in a Ionic4 project.

Look at this example project: https://github.com/coturiv/ionic4-typeorm-starter It has an install script to patch the ReactNativeDriver.js so that it does not try to require react-native-sqlite-storage.

I don’t know why this happens, but I know that TypeOrm only works with this patch in my personal Ionic4 testproject.

@chicrock Hi everyone, 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
  }

getInitialProps is recommended to change getServerSideProps, so you can make a connection from that method. And not from the browser. https://nextjs.org/docs/api-reference/data-fetching/getInitialProps

@jmaister oh~ Next.js 9.3 or newer I gonna upgrade my Next.js. Thanks to replied