Importing a function from a script inside a block

Hi guys, I have a Utils module inside my main script folder (script located at {ProjectRoot}/scripts), and I’d want to import and use some functions from that module from another script inside a block (script located inside {ProjectRoot}/blocks/blockName/scripts). Is there any way to do so? If not, what workaround do you recommend?

I’ve tried both relative and absolute paths when importing the module from inside my block’s script but nothing seems to satisfy the editor’s JS engine, so my guess is that SparkAR is blocking sharing stuff from a different context than the block’s for some reason. Does that make sense? Could someone confirm this theory?

Thanks!

Blocks are meant to be sandboxed environments, so it kind of makes sense that it wouldn’t be able to import any external assets. That would break the portability of the block.

I think the only way to use the same script is to copy it into each block. This can be tedious for development, but you could set up some kind of build process that watches your scripts in the main project and copies them into the blocks when you make changes. There are a lot of web dev frameworks that could do this.

Yeah, that makes sense Josh, thanks for your confirmation and for the workaround! I’ll try something on that line and see what comes up.