You are doing this in wrong way. Magento uses requirejs to load the js dependencies asychronously. This means, js dependencies are loaded only when it really requires. Jquery is also treated as a requirejs module.
So if you want to load your script directly, then instead of defining it in a separate js file, you need to include your code in a phtml file. This is because a separate js file is needed only when you need to create requirejs module.
So here the first step is, add a phtml file in your cms page layout. This is how you should do it:
<?xml version="1.0" ?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<block template="Namespace_Module::script.phtml" class="Magento\Framework\View\Element\Template" name="my.script" />
Here you included the
script.phtml file inside the home page layout. Now it is the time to define this phtml file
So what is the real difference here? Your script is now loaded in the body and hence requirejs and jquery is available to your script. This way your script will be executed without any problem.
PS: Here I assume, you have a working module with name
Namespace_Module. You can also add your layout file via theme too. There are many ways to accomplish the desired scenario.