Variable in import path

I’m unable to load a function from a file based on a variable:

import { now } from './k6-tools.js';
import { publishPayload } from "../" + cable + "/" + cable + "-data.js";

gives:

INFO[0001] doing day:2025-12-14 for n1                   source=console
ERRO[0001] Uncaught (in promise) TypeError: Value is not an object: undefined
running at updatePublish (file:///home/mortenbj/projects/hvdc-k6/tools/endpoints.js:195:32(31))

I can’t use:

if(cable==='nordlink') {
  import { publishPayload } from "../nordlink/nordlink-data.js";
}
else if(cable==='skagerrak') {
  import { publishPayload } from "../skagerrak/skagerrak-data.js";
}
:

It says import only allowed in global scope.

Workaround it to add a wrapper function in which loads the ${cable}-data.js file as a constant for each cable. It means 20+ lines extra per cable.