I am trying to use the library libphonenumber-js.
JavaScript
x
8
1
<body>
2
3
<script src="https://unpkg.com/libphonenumber-js@1.9.9/bundle/libphonenumber-min.js"></script>
4
5
<script src="./js/main.js"></script>
6
7
</body>
8
In my main.js I tried to write a simple code which is from the docs of libphonenumber-js:
JavaScript
1
2
1
const phoneNumber = parsePhoneNumber('+12133734253');
2
However I get this error. Same thing with other functions from the docs.
JavaScript
1
2
1
Uncaught ReferenceError: parsePhoneNumber is not defined
2
In my network tabs I can see that the min.js file is being downloaded. But its functions are not usable for some reason. I tried making a min.js file and using it as well but with not luck.
I also tried many different CDN services which also host this library.
Advertisement
Answer
For anyone wondering:
I found out in the issues page of the repo that you have to use window.libphonenumber or just libphonenumber in front of the function. So
JavaScript
1
5
1
window.libphonenumber.parsePhoneNumberFromString(
2
'(213) 373-42-53 ext. 1234',
3
'US'
4
);
5
Also in my example turns out that the correct function was parsePhoneNumberFromString