Cannot call/import function

Hi,

I have created a simple utility file called utility.js. I have tried the following two ways to import the file:

import * as utility from './utility.js';
import { hello } from './utility.js';

the content of the file is :

function hello () {
    console.log(`Hello`)
}

I call this from the setup function of the main script:

export function setup() {
    hello();
}

I keep getting the following response:
TypeError: Value is not an object: undefined at file:///D:/k6/bdds/main.js:75:4(4).
So it seems that the function is never imported and hello() is undefined. What am i doing wrong here?

Hi @pbains1

I believe you need to mark your hello function as exported for it to be importable?

export function hello() { console.log('Hello') }

As in:

importer.js

import * as utility from './imported.js'

export default function () {
    utility.hello()
}

imported.js

export function hello() {
    console.log('hello')
}

:bowing_man:

Thanks that resolved the issue