question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cleave phone + webpack in vue.js

See original GitHub issue

Hi, i am working in a project made with vue.js, and i am using cleave.js in some components. It was working good, until a couple of weeks ago when we decided to use webpack to build the project. We noticed that our phone input component wasn’t working anymore and it throws an error.

In my component I require it like this (we are also using babel):

import Cleave from 'cleave.js'
require('cleave.js/dist/addons/cleave-phone.mx');

And then create a new instance like this:

this.cleave = new Cleave(this.$el, {
        phone: true,
        phoneRegionCode: 'MX'
});

The error i get is: Error: [cleave.js] Please include phone-type-formatter.{country}.js lib

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
aarongerigcommented, Mar 21, 2019

Hi @patriciabobes, This worked for me:

export default function phoneFormatter() {
  const field = document.getElementById('#phone-number');

  if (field) {
    Promise.all([
      import(/* webpackChunkName: 'cleave' */ 'cleave.js/dist/cleave.min'),
      import(/* webpackChunkName: 'cleave-phone-ch' */ 'cleave.js/dist/addons/cleave-phone.ch'),
    ]).then(([{ default: Cleave }]) => {
      const formatter = new Cleave(field, { phone: true, phoneRegionCode: 'CH' });
      formatter.init(); // This is only so ESLint is happy -> no-new/no-unused-vars conflict
    });
  }
}

Hope this helps!

0reactions
bronzewindcommented, Dec 29, 2018

Hi! It doesn’t works for me. Kind of a different scenario though.

  • Typescript React app
  • yarn add cleave.js @types/cleave.js If it works in your end, could you please share the code? Thanks!
Read more comments on GitHub >

github_iconTop Results From Across the Web

vue-cleave-component - npm
Vue.js component for cleave.js. ... Start using vue-cleave-component in your project by running `npm i vue-cleave-component`.
Read more >
Vue.js 2.x component for Cleave.js
vue -cleave-component · Features · Installation · Usage · Available props · Install in non-module environments (without webpack) · Run examples on your ......
Read more >
How can I combine cleave.js with element in Vue?
js 2 with Element and I would like to make use of Cleave.js for masking. I understand how to make a basic masker...
Read more >
vue-cleave-component - NPM Package Overview - Socket
Clone this repo · You should have node-js >=12.13 and yarn >=1.22 pre-installed · Install dependencies yarn install · Run webpack dev server...
Read more >
cleave - VueJS Generators - GitBook
cleaveOptions · phone · false · Boolean · Enable to trigger phone shortcut mode. This phone mode has to be used together with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found