New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React Native: create tables query fails in release mode with query syntax error #3933
Comments
I tried changing all my entities to use
Once again, it all works absolutely fine in debug mode. |
If it's working and debug and not in prod then it has something to do with configs. I would suggest disabling minification and mangling and see if that helps. It's most common problem in such cases. |
The table creation issue was indeed caused by minification it seems. I was able to continue using the decorator pattern by explicitly mentioning names for all entities and columns like The issue in my second comment persisted though. I wasn't able to get to the bottom of that one. |
I didn't found any related issues. I'm not very familiar with react native, so I probably won't be able to help much more. |
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. |
@naoey Do you have migrations specified in your connection config? I was having the same issue, and it turns out in Release build, the js is minified, and the class names for migrations are mangle. However, these need to have the timestamp as specified here So I found the solution here Simply put, I just installed a different minifier from the default one
and then added this in the
|
No I don't have any migrations in my connection right now. However class and class property names being mangled was the reason for this issue regardless, since that essentially destroyed all my entity and column names. So your solution might also be an viable alternative. |
I don’t believe it is possible for TypeORM to fix this. At the point this code actually runs the names are already mangled by minification. Only way I see is for the user of the library to explicitly mention column and table names as I mentioned in my previous comment. |
This was a problem for us too. We are using Expo.io which doesn't allow you to change how things are minified when deployed, and therefore all migrations break in production. We forked 0.2.16 and hacked in a fix (axomic@febb50c), but would love to get a fix into the main repo. The problem is in:
getMigrations() uses introspection on the constructor to get the class name, but if the code is minified the class name is typically just a single letter!
We added an optional "name" property to MigrationInterface so that we could explicitly name a migration, rather than introspecting the class name, and then changed the line above to:
We aren't the only ones with this issue, here are a few examples of people having to find workarounds. facebook/metro#154 (comment) |
I think this fix isn't a part of typeorm package because nobody made a PR for it. As for original issue - minification takes place before TypeOrm code is run, so unfortunately we can do nothing about that. |
I think the documentation here needs to be improved. Sure enough, I ran into this same issue only on the built version and updating each |
The error occurs because of minify/uglify process, workaround was disable this for class and function names: node_modules\metro-config\src\defaults\index.js 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 inlines single-use functions, which cause perf regressions.
reduce_funcs: false
}
}, still looking for a better solution since the mentioned package metro-minify-terser is not avaliable anymore, im thinking in change this configurations via metro.config, or switch minify package for https://github.com/terser/terser |
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 The builder would be:
A generated select query would be
which would fail for obvious reasons. The only proper solution is to update minifireConfig via
|
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:
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:
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:
The text was updated successfully, but these errors were encountered: