I am trying to load an .mjs file
import {msg} from “./general.mjs”;
and am getting the error
SyntaxError: Unexpected token `import'
Stack traceback:
@file:///home/les/Documents/act-fast/Assets/Ignored/TiledProject/extensions/moo.js:1
The file is “general.mjs” and it is located in the same extensions folder as the main code.
The main code file is found and works.
It contains 1 exported function. It has no syntax errors.
This is it:
export function msg(t){
tiled.alert(t);
}
What could be going on?
EDIT:
In fact I figured this out.
In order to use an import it must be named .mjs (as I did). However an .mjs file can only be imported by another .mjs file.
My main file was .js and that wasn’t going to work. I renamed it .mjs and now my import works.
Is this a bug or expected?
In the documentation there is no mention of this and the linked javascript module documentation states that you should be able to import a .mjs to a .js file.
Perhaps the Tiled documentation needs a note about this issue?