question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

React Native: create tables query fails in release mode with query syntax error

See original GitHub issue

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:

I only added TypeORM to my project last week. Everything was working great while developing but as soon as I began making release builds of my app the entire database stopped working. Turning on logging shows me this:

2019-04-03 19:08:05.864 [error][tid:com.facebook.react.JavaScript] 'query failed: ', 'CREATE TABLE "temporary_t" ()'
2019-04-03 19:08:05.866 [error][tid:com.facebook.react.JavaScript] 'error: ', { message: 'near ")": syntax error', code: 5 }

I’ve been unable to identify what could be causing this and from a cursory search I haven’t been able to find any other reports of this issue.

I believe the error is being thrown immediately on creation of the database in the root of the app, and no further database related operation work in the application. My initialisation code:

const sqliteConnectionManager = getConnectionManager();
const connection = sqliteConnectionManager.create({
  type: 'react-native',
  database: DATABASE_NAME,
  synchronize: true,
  logging: true,
  // migrations,
  entities,
  location: 'default',
});

await connection.connect();

I’m using plain JavaScript in this project, not TypeScript. Any help would be much appreciated.

May also be worth mentioning I’m using ES6 with decorators for defining my entities, like so:

@Entity()
class ReferenceDataGroup {
  @PrimaryColumn('text')
  groupId;

  @Column({ type: 'text', nullable: true })
  lastModified;

  @OneToMany(() => ReferenceDataValue, rdValue => rdValue.groupId, { eager: false })
  values;
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

5reactions
naoeycommented, Apr 23, 2019

Considering my original problem was resolved I suppose this issue can be closed.

Though it may be worth adding a quick but prominent mention in the setup for React Native that when using the decorator pattern for defining entities with ES6 and Babel, explicit table and column names need to be defined if the compiled code is going to be minified. Since minification is on by default in RN projects, I imagine other users may keep running into this issue.

2reactions
kristfalcommented, May 14, 2020

Just a heads up here: I ran into a related issue, but it was caused by the queryBuilder. While minification seems to work for regular queries as the minified aliases would make queries consistent, using the queryBuilder with hardcoded strings would break due to the following:

The builder would be:

getConnection()
    .getRepository(Table)
    .createQueryBuilder()
    .where('table.id = :id', {
      id,
    })
    .getMany();

A generated select query would be

SELECT t.id from table t WHERE table.id = 1

which would fail for obvious reasons. The only proper solution is to update minifireConfig via metro.config.js, ex:

module.exports = {
  transformer: {
    minifierConfig: {
      keep_classnames: true, // enable to fix typeorm
      keep_fnames: true, // enable to fix typeorm
      mangle: {
        toplevel: false,
        keep_classnames: true, // enable to fix typeorm
        keep_fnames: true, // enable to fix typeorm
      },
      output: {
        ascii_only: true,
        quote_style: 3,
        wrap_iife: true,
      },
      sourceMap: {
        includeSources: false,
      },
      toplevel: false,
      compress: {
        reduce_funcs: false,
      },
    },
  },
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

react native app works on debug mode, but not works release ...
Based on the information provided, it seems like you're loading different bundles when switching between debug and release modes.
Read more >
Addressing common errors in React Native - LogRocket Blog
Explore common React Native errors such as "command not found" and learn about their causes and potential solutions.
Read more >
Suspense for Data Fetching (Experimental) - React
React 18 was released with support for concurrency. However, there is no “mode” anymore, and the new behavior is fully opt-in and only...
Read more >
Node.js v19.3.0 Documentation
A subclass of Error that indicates the failure of an assertion. ... The type of resources created by Node.js itself can change in...
Read more >
Build an Offline-First React Native Mobile App with Expo and ...
That will configure our app correctly to use Sync and set it into Development Mode. Read It Later - Maybe. Now we can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found