WTF WTF - 2 years ago 88
Javascript Question

Exported Function isn't a Function?

Not sure why it's not viewing this as a function:


export default function(callback){
return callback();


import {myModule} from '../../src/impl.js'
import {expect} from 'chai';

const module = myModule;

describe('', () => {

it('should callback when resolve is invoked', () => {
module(resolve => {
}).then(value => {


TypeError: module is not a function

Answer Source

module isn't a function because where it receives its value, myModule, also isn't a function.

And, that is because you aren't using quite the correct syntax to import the export default. For that, you'll want to remove the braces around myModule:

import myModule from '../../src/impl.js'

From MDN:


import *defaultMember* from *"module-name"*;

With the braces, the import will match a particular export by its name.

import { myModule } from '...';

Corresponds to either:

export let myModule = ...;
export function myModule() { ... };

And, impl.js doesn't export anything actually named myModule.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download