Error Transform failed with 1 error

I could isolate what’s causing it I think.
<script type="module"> await document.querySelector("needle-engine")?.getContext(); <-- THIS! </script>

by user 732122195614105653

In essence, this is what I’m trying to do. It seems to work fine when running local, but Build fails when the await line is in index.html.

    <script>
        // hack for simple-peer
        window.global = window;
        var parcelRequire;
    </script>
    <script type="module" src="./src/generated/gen.js"></script>
    <script type="module" src="./src/main.ts"></script>

    <div class="container">
        <div class="content">
            <needle-engine loadfinished="loadingFinished"></needle-engine>
            <div id="ui" class="overlay-container">
            </div>
        </div>
    </div>

    <script type="text/javascript">
        function loadingFinished() {
            console.log("FINISHED!");
        }
    </script>

    <script type="module">
        import { MyClass } from 'com.unity.mypackage/MyClass'; // import my custom class

        await document.querySelector('needle-engine')?.getContext(); // wait for content/context?

        var myUI = document.querySelector('#ui'); // get the UI

        var myClassInstance = Needle.findObjectOfType(MyClass);
        if (myClassInstance) {
            // populate HTML UI from Needle content
        }
    </script>
</body>```

*by user 732122195614105653*

I think you can not await in global scope like that - you could chain it using getContext().then(ctx => { ... }); or call a method that is async (e.g. async function setup() { ... } setup())

Ah I knew I was doing it wrong :slightly_smiling_face: Let me try that. Thanks!

by user 732122195614105653

It works! Thank you so much :slightly_smiling_face:

by user 732122195614105653

Great! happy to help :slightly_smiling_face:

Would you mind sharing your working example here? :slightly_smiling_face:

Let me check that I can share what I’m doing.

by user 732122195614105653