Search code examples
javascriptjavascript-objectstypeerror

JavaScript Error: Object(...) is not a function


I have a simple example: util.js and app.js are in the same directory.

In util.js

export function existy(x)
{
   return x !== null && x != undefined;
}

In app.js

import {existy} from 'util';

var x = undefined;
if (!existy(x))
{
    console.log('x doesn't exist');
}

But I got a TypeError: Object(...) is not a function on the line I use existy function in app.js. What makes it think existy is not a function?

How can I fix it? Thanks!


Solution

  • you should import like this:

    import {existy} from './util';