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
autoNumeric does not work with Browserify #388
Comments
Hey @jsmarsch, could you please post a gist or a codepen with the files needed to reproduce this error, as well as the commands you are typing? For information, autoNumeric is built with Webpack. We are therefore not experts in Browserify! |
Sorry -- I'm not a browserify expert either :( I want to help, but I'm facing a delivery deadline of my own right now, and I just don't have the free moments to set up a full build environment with gulp, browserify, npm, tsify, and get it all working (it took a couple of weeks the first time!) |
No problem, whenever you feel ready to help us debug this one, we'll be here! |
Not sure if my comment helps, I had a similar problem. I noticed the "main" key in the package.json object targets the "src/autoNumeric.js". So I didn't load the default one, but instead loaded the dist one. That worked out of the box on browserify. |
Thanks for your comment @bs-thomas, it does help to know there is a workaround, and perhaps even pinpoint why this is not working. |
@jsmarsch, @bs-thomas, is this problem resolved with the latest version in Much has changed since |
@AlexandreBonneau Actually I'm using 2.0.8 when my problem happened. Thus, I did this in my "browser" key in my package.json in order to resolve the issue. So for sure, this was still happening in 2.0.8.
|
@bs-thomas unfortunately I'm not sure how I could correct that behavior for Browserify on our end. Was that working at any point since we switched to webpack? Would it also be possible to try with your setup if the latest |
FYI.. I just installed beta 4.0.0 via NPM and required it in my Browserify project. I did initially get the error message shown in this thread. I added the following "Browser" element though in package.json and that got rid of the error (per @AlexandreBonneau ). thx! I am seeing one problem though that I have not been able to fix. I can initialize AutoNumeric on a class of elements. I have not been able to do an update. I tried some of the syntax I saw in a ES6 fix. Here's my code... Then.. to do the update.. I am using this.. This gives me... "anElement.update is not a function" Does anyone know how to make an update work? If I do another init, of course I get the JS warning message. Thanks. |
Hi @whiskeysauer, thanks for your input on that issue. We'll have to see what side effects adding that About your request on the As you can see in the doc, anElementsArray = new AutoNumeric.multiple('.currency', { currencySymbol : '$' });
anElementsArray.forEach(anElement => {
anElement.update({ currencySymbol : '$' });
}); Or, if you need all the given AutoNumeric-managed element to have the exact same option on initialization (you can change their option separately after), you could first initialize the first element with the options you want, then use the anElement1 = new AutoNumeric('.currency', { currencySymbol : '$' });
anElement1.init(domElement2)
.init(domElement3)
.init(domElement4);
anElement1.global.update({ options }); // Update the settings of each autoNumeric-managed elements
anElement1.global.unformat(); // etc. I hope that helps. |
For info, the documentation about the |
I recognize that calling |
…OM elements, or a CSS selector as its first argument. This has been discussed in issue #388 comments. Signed-off-by: Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
Ok, so to simplify things a bit, you can now directly use anElement1 = new AutoNumeric(domElement1, { currencySymbol : '$' });
anElement1.init('.currency'); // This potentially selects multiple elements
anElement1.global.update({ options });
anElement1.global.unformat(); // etc.
// or use
anElement1.init([domElement2, domElement3, domElement4]); The documentation has been updated accordingly. |
I've opened #467 which fixes the issue with Browserify. @AlexandreBonneau in the |
Thanks for the PR @munkychop. I changed the target to So, since this is not needed and changing it back to |
One question though, shouldn't we target the non-minified version of the library? |
@AlexandreBonneau in my PR I am targeting the non-minified version. |
Ah sorry, I meant shouldn't we target the minified version, in order to produce a smaller bundle? |
Personally, I think it's better to target the non-minified version for setups like Browserify, because these kinds of projects are typically minified at build time. Targeting the non-minified version avoids double-minification. |
Ok, thanks for your input |
👍🏽 |
Fix issue #388 autoNumeric does not work with Browserify
…ility) Signed-off-by: Alexandre Bonneau <alexandre.bonneau@linuxfr.eu>
We are using npm to manage our packages, and commonjs + browserify to handle module loading.
I get the following error during the browserify build:
(this is gulp executing browserify):
Looks like an unexpected token while parsing autoNumeric.js
The text was updated successfully, but these errors were encountered: