Microsoft didn't make modern versions of the ScriptEditor or ContentEditor web parts because they felt that users injecting script directly into pages had too great a potential to destabilize the page or unintentionally cause data loss.
Their solution to this problem was the SharePoint Framework. Using the SharePoint Framework developers can still inject JavaScript into pages, however that script needs to be contained in a package and deployed to an App Catalog first. The concept is that administrators, who have control over the access to the App Catalog, will have the opportunity to review any code before it gets deployed.
With all of that said, the SharePoint developer community felt that despite Microsoft's concerns there was value in having modern versions of the ScriptEditor or ContentEditor web parts so they created their own. Please see the following blog posts for more information.
Perhaps the only SharePoint Framework web part you will ever need (ScriptEditor)
https://www.techmikael.com/2017/03/perhaps-only-sharepoint-framework-web.html
Perhaps The Only OTHER SharePoint Framework Web Part You Will Ever Need (ContentEditor)
https://info.paitgroup.com/blog/perhaps-the-only-other-sharepoint-framework-web-part-you-will-ever-need