Skip to content
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

angular-input-masks-standalone doesnt work with requirejs #169

Open
salmanasiddiqui opened this issue Mar 26, 2016 · 5 comments
Open

angular-input-masks-standalone doesnt work with requirejs #169

salmanasiddiqui opened this issue Mar 26, 2016 · 5 comments

Comments

@salmanasiddiqui
Copy link

salmanasiddiqui commented Mar 26, 2016

Added angular-input-masks-standalone in requirejs config.

gives the following error on load:
angular-input-masks-standalone.js:3969 Uncaught TypeError: StringMask is not a constructor

angular: 1.3.13
angular-input-masks: 2.0.0

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/32283530-angular-input-masks-standalone-doesnt-work-with-requirejs?utm_campaign=plugin&utm_content=tracker%2F1022469&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F1022469&utm_medium=issues&utm_source=github).
@aj07mm
Copy link

aj07mm commented Apr 25, 2016

same here 2.2.0

angular-input-masks-standalone.js:4468 Uncaught TypeError: StringMask is not a constructor

StringMaks is an empty object

@aj07mm
Copy link

aj07mm commented Apr 26, 2016

this works:

require.config({
    paths: {
        'angular': 'js/libs/angular/angular.min',
        'moment': 'js/libs/moment/moment.min',
        'string-mask': 'js/libs/string-mask/string-mask',
        'br-validations': 'js/libs/br-validations/br-validations',
        'angular-input-masks': 'js/libs/angular-input-masks/angular-input-masks',
    },
    shim: {
        'angular-input-masks': ['angular', 'string-mask', 'moment', 'br-validations'],
        'angular': {exports: 'angular'}
    },
    baseUrl: '/static'
});

require(['modules/app'], function(app) {
    app.init();
});

But we actually need to do this imports in a different way inside the npm module.
Seems like requireJS is not doing his job there

@aj07mm
Copy link

aj07mm commented Apr 27, 2016

as a final note: don't use angular-input-masks on a requirejs based application.

@mateusmcg
Copy link

There is a workaround that did the trick for me, i imagine it could help someone...

/** Workaround to make angular-input-mask work with requirejs  */
var _require = require;

require.config({
    waitSeconds: 15,

    baseUrl: "",

    paths: {
        'angular-input-masks': 'assets/libs/angular-input-masks/angular-input-masks',
        'string-mask': 'assets/libs/string-mask/string-mask',
        'br-validations': 'assets/libs/br-validations/br-validations',
        'moment': 'assets/libs/moment/moment'
    },
    shim: {
        "angular": {
            exports: "angular"
        },
        'angular-input-masks': {
            deps: ['angular', 'string-mask', 'moment', 'br-validations'],
            init: function () {
                require = _require;
            }
        }
    },

    deps: ['app']
});

The two main points beeing:
• Instantiate a new require variable and create the init function inside 'angular-input-masks' shim, like shown above.
• You should import the angular-input-masks.js and NOT the standalone version.

@norok
Copy link

norok commented Feb 9, 2018

On the latest version this workaround does not work anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants