Unexpected Token "import" in script

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?

Hmm, the documentation notes:

When using the .mjs extension, script files are loaded as JavaScript modules. They will then be able to use the import and export statements to split up their functionality over multiple JavaScript files. Such extensions also don’t pollute the global scope, avoiding potential name collisions between different extensions.

In wording this, I tried to make it clear that import and export can only be used within modules, but maybe it should be more explicit?

I read that section and didn’t make the connection.
How about an additional sentence?

When using the .mjs extension, script files are loaded as JavaScript modules. They will then be able to use the importandexportstatements to split up their functionality over multiple JavaScript files. Note that import and export are not valid statements when used in files with the .js extension.