Split Code in multiple Files

Hello,
I want to sort my code and put it in different files. I made a function in a new file and put it in my main file. But I get an error message.

Uncaught SyntaxError: export declarations may only appear at top level of a module [modelload.js:1]
Uncaught SyntaxError: import declarations may only appear at top level of a module

Dont´t wonder it is runnig on TYPO3

example Code:
modelload.js:

export function modelload(){
//some code
}

mainrender.js:
var createScene = function () {
//some code
import {modelload} from ‘./modelload.js’;
modelload();
//some code
}

My HTML:

  <script src="/typo3conf/ext/alfavet_produktion/Resources/Public/JavaScript/Dist/DDD/modelload.js?1646120445"></script>
    <script src="/typo3conf/ext/alfavet_produktion/Resources/Public/JavaScript/Dist/DDD/mainrender.js?1646120443"></script>

Thanks for the responses in advance.

Hi @Lauritz_Offe,

You need to add type=module to the js file that contains the util functions.

<script type="module" src="modelload.js"></script>
1 Like

Hello @Lauritz_Offe just checking in, was your question answered?