rxdb: Unexpected token: keyword (function) UglifyJs

hi author, i trying to use rxdb with vuejs + cordova ( quasar framework ) but when build this bug happend.

ERROR in js/0.bcc8ac658f5ce5687243.js from UglifyJs
Unexpected token: keyword (function) [js/0.bcc8ac658f5ce5687243.js:590,6]

more detail i posted here: https://github.com/quasarframework/quasar/issues/573 this error make app can not run on mobile cordova, please help !

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 31 (21 by maintainers)

Most upvoted comments

I released 4.0.2 a few seconds ago. One problem was the usage of constructor.name=='WhatEver' which does not work after minification. Another thing was that we still had es7-things in the es6-build which of course broke UglifyJS

Hi @lyquocnam. This error is produced by UglifyJS whenever it tries to ‘uglify’ a function that has been designated as an asynchronous function.

Depending on how the webpack setup is defined for the quasar-cli, you will need to run this bundle through a transpiler such as babel first. It looks like that function is being required in wholesale from rxjs somewhere.

NOTE: Offending function in your prod bundle;

async function assertThrowsAsync(test, error = Error, contains = '') { ... }

@lyquocnam I could reproduce this on the angular2-example. I will investigate…

@varbrad Great. I will do a new release tomorrow evening. (now +20 hours)

@lyquocnam I created a branch where I commited a new build. Could you add rxdb to your package.json by the following commit-hash:

rxdb: "git+https://github.com/pubkey/rxdb/commit/d3d70e919f10d7f5178f6febeb6707ed089c8100"

Then re-run npm install and check if the build works now.

A few notes;

  • cross-env should be declared as a dev-dependency, I had to install it.
  • npm run build gives me an error, seems like an async function within the scripts/transpile.js file is tripping up NodeJS.
  • npm run build:es works, and seems to look better (no async stuff), but UglifyJS still blows up in my face with some errors.

Not sure if this is an option, but could the ‘ES’ module version just not be uglified? Looking at most other modules such as vue, redux et al, they don’t uglify their ES module builds.

Plus, can UglifyJS even handle the export ES syntax?

@varbrad Ah, you are right. Forgot to add the link itself 😃 Edited the post.

@varbrad Hi, Please read this post from Rich Harris explaining what “jsnext:main” is and how it should be used by package owners, and then the next comment. Seems like rxdb has chosen option 3, but this complicates things a lot for devs using Webpack which have to do extra configuration. You might want to chose another option so that this will work “out of the box” with Webpack too. Most users just drop a package and search for replacement when having such problems – not to mention not everyone is a Webpack wizard 😃 Just my opinion.

EDIT: forgot to add link 😃 https://github.com/reactjs/redux/issues/1042#issuecomment-157129818

Ok I think I have figured it out. Webpack is using the module source from rxdb when being built. This results in webpack just using the source files rather than the dist files.

This means the async/await stuff just gets put into the resulting bundle, and then uglify-js gets confused when it sees them when attempting to uglify the source.

Also, if babel (or similar) is running within the quasar build step, then it will be ignoring node_modules (presumably, I haven’t checked) and voila, there’s the issue.