In preview mode your files aren't uploaded anywhere, so they cannot be fetched normally. This is what the Asset Manager is for: it handles requests for you to make sure they work on all platforms. In this case you need to use something like this in an async function:
scriptElem.src = await runtime.assets.getProjectFileUrl("myscript.js");