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

Getting error while using utilsScript #1618

Closed
udit-001 opened this issue May 15, 2024 · 6 comments
Closed

Getting error while using utilsScript #1618

udit-001 opened this issue May 15, 2024 · 6 comments

Comments

@udit-001
Copy link

udit-001 commented May 15, 2024

Plugin version

v23.0.4

Expected behaviour

No errors should be there

Actual behaviour

Getting the following errors in browser console:

Brave Version 1.65.132 Chromium: 124.0.6367.202

Uncaught SyntaxError: Unexpected token 'export'

Firefox 125.0.3

Uncaught SyntaxError: export declarations may only appear at top level of a module

Initialisation options

I am not using webpack or any other bundler, I am using vanilla JavaScript and specifying the utilsScript as follows:

 utilsScript: "/static/js/utils.js",

Here's the script for reference:

var fieldDiv = document.querySelector("field-phone_number");
window.addEventListener('load', function (event) {
    var input = document.querySelector("#id_phone_number");
    var jsConfig = {
      initialCountry: "id", 
      separateDialCode: true,
      strictMode: true,
      onlyCountries: ["in", "id"]
    }
    const widgetConfig = {
        ...jsConfig,
        useFullscreenPopup: true,
        utilsScript: "/static/phones/js/utils.js",
        hiddenInput: function(telInputName) {
            return {
                phone: "phone_number_1"
            };
        }
    }
    window.intlTelInput(input, widgetConfig);
});

Comments

Should I include utils script in a different way in my project?

@jackocnr
Copy link
Owner

What version of the plugin are you using?

@udit-001
Copy link
Author

I'm using v23.0.4

@jackocnr
Copy link
Owner

Hmm that's strange. Do you see the same issue on the demo site?

@udit-001
Copy link
Author

No, I don't see that error on the demo site.

Can I use build/js/intlTelInputWithUtils.js instead of using a separate utils file?

@jackocnr
Copy link
Owner

Can I use build/js/intlTelInputWithUtils.js instead of using a separate utils file?

You can if you don't mind the filesize, as the utils script is aprx 260kb.

Or if you want to try and figure out this issue, it would help if you could find the minimal set of code that reproduces the problem and put that in a CodePen, so I can take a look. Here is an example pen with the plugin up and running - feel free to fork this if it helps.

@udit-001
Copy link
Author

Thank you for your help, the issue has been resolved.

It appears that the utils file was being included as a script tag as well. I was attempting to integrate this with Django, and there was a slight configuration issue, which caused the error to occur.

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

No branches or pull requests

2 participants