Is there a way to import my own javascript module from a procedural proto node? I have a .js file with some function defined that I would like to use in several .proto files. The file is called configure_proto.js and it is in the same root folder than the protos.
When I try to import that module using import * as Config from 'configure_proto.js' it fails because it searches it in the temporal folder created by webots. I have also tried to dynamically copy the file to the temporary folder so that I can access it:
let protoPath = context.proto;
protoPath = protoPath.substring(0, protoPath.lastIndexOf('/') + 1);
let src = protoPath + 'configure_proto.js';
let dst = 'configure_proto.js';
wbfile.writeTextFile(dst, wbfile.readTextFile(src));
import * as Config from 'configure_proto.js';
This also fails with the following error:
error: Template engine error: failed to import JavaScript template: Could not open module file:///tmp/webots/jprieto/1234/configure_proto.js for reading
The interesting thing is that if I do not use the last line which imports the copied file, the code works and I can see that the file has been correctly copied to the folder, but there is no way to import it.
What can I do to solve this issue?