Search code examples
javascriptfunctionwebpacktypeof

Using webpack in my application and can't use javascript's typeof directive


So everytime I try to use typeof, like on the example below

window.clone = function clone(obj){
    if(obj === null || (typeof obj) !== 'object')
        return obj;

    var temp = new obj.constructor(); 
    for(var key in obj)
        temp[key] = clone(obj[key]);

    return temp;
};

It throws me this error

Cannot find module '@babel/runtime/helpers/typeof'

That's pretty ridiculous. What can I do in this situation? Thanks in advance.


Solution

  • npm install --save-dev @babel/runtime worked for me :)

    Sources:

    https://github.com/babel/babel/issues/7514

    https://babeljs.io/docs/en/babel-runtime